Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add registry collection support #120

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 53 additions & 24 deletions vscode-car-plugin/src/main/java/org/wso2/maven/CAppHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import javax.xml.namespace.QName;
Expand Down Expand Up @@ -218,20 +219,55 @@ void processRegistryResources(File resourcesFolder, String archiveDirectory, Lis
for (OMElement artifact : artifactChildElements) {
String name = artifact.getAttributeValue(new QName(Constants.NAME));
String version = artifact.getAttributeValue(new QName(Constants.VERSION));
OMElement item = getFirstChildWithName(artifact, Constants.ITEM);
String fileName = item.getFirstChildWithName(new QName(Constants.FILE)).getText();
String path = item.getFirstChildWithName(new QName(Constants.PATH)).getText();
File registryResource;
if (path.startsWith(Constants.GOV_REG_PREFIX)) {
path = path.substring(Constants.GOV_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.GOV_FOLDER + path + "/" + fileName);
} else {
path = path.substring(Constants.CONF_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.CONF_FOLDER + path + "/" + fileName);
}
if (!registryResource.exists()) {
mojoInstance.logError("Registry resource " + path + "/" + fileName + " does not exist");
continue;
String commonPath = Paths.get(archiveDirectory, name + "_" + version).toString();
if (artifact.getFirstChildWithName(new QName(Constants.ITEM)) != null) {
OMElement item = getFirstChildWithName(artifact, Constants.ITEM);
String fileName = item.getFirstChildWithName(new QName(Constants.FILE)).getText();
String path = item.getFirstChildWithName(new QName(Constants.PATH)).getText();
File registryResource;
if (path.startsWith(Constants.GOV_REG_PREFIX)) {
path = path.substring(Constants.GOV_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.GOV_FOLDER + path + "/" + fileName);
} else {
path = path.substring(Constants.CONF_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.CONF_FOLDER + path + "/" + fileName);
}
if (!registryResource.exists()) {
mojoInstance.logError("Registry resource " + path + "/" + fileName + " does not exist");
continue;
}
org.wso2.developerstudio.eclipse.utils.file.FileUtils.copy(registryResource,
new File(Paths.get(archiveDirectory, name + "_" + version, Constants.RESOURCES,
fileName).toString()));
OMElement infoElement = getElement(Constants.RESOURCES, Constants.EMPTY_STRING);
infoElement.addChild(item);
org.wso2.developerstudio.eclipse.utils.file.FileUtils.createFile(
new File(commonPath, Constants.REG_INFO_FILE), serialize(infoElement));
} else if (artifact.getFirstChildWithName(new QName(Constants.COLLECTION)) != null) {
OMElement collection = getFirstChildWithName(artifact, Constants.COLLECTION);
String directory = collection.getFirstChildWithName(new QName(Constants.DIRECTORY)).getText();
String path = collection.getFirstChildWithName(new QName(Constants.PATH)).getText();
File registryResource;
if (path.startsWith(Constants.GOV_REG_PREFIX)) {
path = path.substring(Constants.GOV_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.GOV_FOLDER + path);
} else {
path = path.substring(Constants.CONF_REG_PREFIX.length());
registryResource = new File(registryFolder, Constants.CONF_FOLDER + path);
}
if (!registryResource.exists()) {
mojoInstance.logError("Registry resource " + path + " does not exist");
continue;
}

File destFile = new File(Paths.get(archiveDirectory, name + "_" + version, Constants.RESOURCES,
directory).toString());
destFile.mkdirs();
FileUtils.copyDirectory(registryResource, destFile);
OMElement infoElement = getElement(Constants.RESOURCES, Constants.EMPTY_STRING);
infoElement.addChild(collection);
org.wso2.developerstudio.eclipse.utils.file.FileUtils.createFile(
new File(commonPath, Constants.REG_INFO_FILE), serialize(infoElement));
}
dependencies.add(new ArtifactDependency(name, version, Constants.SERVER_ROLE_EI, true));
Artifact artifactObject = new Artifact();
Expand All @@ -242,16 +278,9 @@ void processRegistryResources(File resourcesFolder, String archiveDirectory, Lis
artifactObject.setFile(Constants.REG_INFO_FILE);

String artifactDataAsString = createArtifactData(artifactObject);
String commonPath = Paths.get(archiveDirectory, name + "_" + version).toString();
org.wso2.developerstudio.eclipse.utils.file.FileUtils.createFile(
new File(commonPath, Constants.ARTIFACT_XML), artifactDataAsString);
org.wso2.developerstudio.eclipse.utils.file.FileUtils.copy(registryResource,
new File(Paths.get(archiveDirectory, name + "_" + version, Constants.RESOURCES,
fileName).toString()));
OMElement infoElement = getElement(Constants.RESOURCES, Constants.EMPTY_STRING);
infoElement.addChild(item);
org.wso2.developerstudio.eclipse.utils.file.FileUtils.createFile(
new File(commonPath, Constants.REG_INFO_FILE), serialize(infoElement));

}
} catch (IOException | XMLStreamException | MojoExecutionException e) {
mojoInstance.logError("Error occurred while processing registry resources");
Expand Down Expand Up @@ -464,8 +493,8 @@ void createDependencyArtifactsXmlFile(String archiveDirectory, List<ArtifactDepe
/**
* Method to process class mediators in the project and create corresponding files in the archive directory.
*
* @param dependencies list of dependencies to be added to artifacts.xml file
* @param project VSCode maven project
* @param dependencies list of dependencies to be added to artifacts.xml file
* @param project VSCode maven project
*/
void processClassMediators(List<ArtifactDependency> dependencies, MavenProject project) {
String jarName = project.getArtifactId() + "-" + project.getVersion() + ".jar";
Expand Down
2 changes: 2 additions & 0 deletions vscode-car-plugin/src/main/java/org/wso2/maven/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Constants {
static final String NAME = "name";
static final String FILE = "file";
static final String ITEM = "item";
static final String COLLECTION = "collection";
static final String DIRECTORY = "directory";
static final String PATH = "path";
static final String DEPENDENCY = "dependency";
static final String INCLUDE = "include";
Expand Down