use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project liferay-ide by liferay.
the class MavenProjectBuilder method initBundle.
public IStatus initBundle(IProject project, String bundleUrl, IProgressMonitor monitor) throws CoreException {
if (bundleUrl != null) {
File pomFile = FileUtil.getFile(project.getFile("pom.xml"));
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
MavenXpp3Writer mavenWriter = new MavenXpp3Writer();
try (FileReader reader = new FileReader(pomFile)) {
Model model = mavenReader.read(reader);
if (model != null) {
Build build = model.getBuild();
Plugin plugin = build.getPluginsAsMap().get("com.liferay:com.liferay.portal.tools.bundle.support");
if (plugin != null) {
try (FileWriter fileWriter = new FileWriter(pomFile)) {
Xpp3Dom origin = (Xpp3Dom) plugin.getConfiguration();
Xpp3Dom newConfiguration = new Xpp3Dom("configuration");
Xpp3Dom url = new Xpp3Dom("url");
url.setValue(bundleUrl);
newConfiguration.addChild(url);
plugin.setConfiguration(Xpp3Dom.mergeXpp3Dom(newConfiguration, origin));
mavenWriter.write(fileWriter, model);
}
}
}
} catch (Exception e) {
LiferayMavenCore.logError("Could not write file in" + pomFile, e);
}
}
IMavenProjectFacade facade = MavenUtil.getProjectFacade(project, monitor);
if (_execMavenLaunch(project, MavenGoalUtil.getMavenInitBundleGoal(project), facade, monitor)) {
return Status.OK_STATUS;
}
return LiferayMavenCore.createErrorStatus("run init-bundle error");
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class PluginBundleManager method install.
public PluginBundle install(MavenPluginBundle mavenPluginBundle, List<SPluginInformation> plugins, boolean strictDependencyChecking) throws Exception {
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = mavenPluginBundle.getPluginVersionIdentifier();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (InputStream pomInputStream = mavenPluginBundle.getPomInputStream()) {
model = mavenreader.read(pomInputStream);
}
if (plugins == null) {
try (InputStream inputStream = mavenPluginBundle.getJarInputStream()) {
try (JarInputStream jarInputStream = new JarInputStream(inputStream)) {
JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
while (nextJarEntry != null) {
if (nextJarEntry.getName().equals("plugin/plugin.xml")) {
// Install all plugins
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(new FakeClosingInputStream(jarInputStream));
plugins = new ArrayList<>();
pluginManager.processPluginDescriptor(pluginDescriptor, plugins);
for (SPluginInformation info : plugins) {
info.setInstallForAllUsers(true);
info.setInstallForNewUsers(true);
}
break;
}
nextJarEntry = jarInputStream.getNextJarEntry();
}
}
}
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
loadDependencies(mavenPluginBundle.getVersion(), strictDependencyChecking, model, delegatingClassLoader);
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (Files.exists(target)) {
throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
}
InputStream jarInputStream = mavenPluginBundle.getJarInputStream();
try {
Files.copy(jarInputStream, target);
} finally {
jarInputStream.close();
}
return loadPlugin(pluginBundleVersionIdentifier, target, mavenPluginBundle.getPluginBundle(), mavenPluginBundle.getPluginBundleVersion(), plugins, delegatingClassLoader);
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class PluginBundleManager method loadFromPluginDir.
public PluginBundle loadFromPluginDir(PluginBundleVersionIdentifier pluginBundleVersionIdentifier, SPluginBundleVersion pluginBundleVersion, List<SPluginInformation> plugins, boolean strictDependencyChecking) throws Exception {
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (!Files.exists(target)) {
throw new PluginException(target.toString() + " not found");
}
SPluginBundle sPluginBundle = new SPluginBundle();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (JarFile jarFile = new JarFile(target.toFile())) {
ZipEntry entry = jarFile.getEntry("META-INF/maven/" + pluginBundleVersion.getGroupId() + "/" + pluginBundleVersion.getArtifactId() + "/pom.xml");
try (InputStream inputStream = jarFile.getInputStream(entry)) {
model = mavenreader.read(inputStream);
}
}
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
loadDependencies(model.getVersion(), strictDependencyChecking, model, delegatingClassLoader);
for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
if (isDependencyProvidedOrIfcPlugins(dependency)) {
// TODO Skip, we should also check the version though
} else {
PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependency.getGroupId(), dependency.getArtifactId());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) {
if (strictDependencyChecking) {
VersionRange versionRange = VersionRange.createFromVersion(dependency.getVersion());
String version = pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion();
ArtifactVersion artifactVersion = new DefaultArtifactVersion(version);
if (versionRange.containsVersion(artifactVersion)) {
// OK
} else {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + version + ") does not comply to the required version (" + dependency.getVersion() + ")");
}
} else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
}
} else {
if (isDependencyProvided(dependency)) {
} else {
// this must be IfcPlugins then?
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependency.getGroupId(), dependency.getArtifactId());
try {
Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
} catch (Exception e) {
}
}
}
}
}
return loadPlugin(pluginBundleVersionIdentifier, target, sPluginBundle, pluginBundleVersion, plugins, delegatingClassLoader);
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class PluginBundleManager method loadJavaProject.
public PluginBundle loadJavaProject(Path projectRoot, Path pomFile, Path pluginFolder, PluginDescriptor pluginDescriptor, boolean resolveRemoteDependencies) throws PluginException, FileNotFoundException, IOException, XmlPullParserException {
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = null;
try (FileReader reader = new FileReader(pomFile.toFile())) {
model = mavenreader.read(reader);
}
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(model.getGroupId(), model.getArtifactId(), model.getVersion());
if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleVersionIdentifier.getPluginBundleIdentifier())) {
throw new PluginException("Plugin " + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getHumanReadable() + " already loaded (version " + pluginBundleIdentifierToPluginBundle.get(pluginBundleVersionIdentifier.getPluginBundleIdentifier()).getPluginBundleVersion().getVersion() + ")");
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
PublicFindClassClassLoader previous = new PublicFindClassClassLoader(getClass().getClassLoader()) {
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
return null;
}
@Override
public URL findResource(String name) {
return null;
}
@Override
public void dumpStructure(int indent) {
}
};
Set<org.bimserver.plugins.Dependency> bimServerDependencies = new HashSet<>();
pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(new PluginBundleIdentifier(model.getGroupId(), model.getArtifactId()), model.getVersion());
previous = loadDependencies(bimServerDependencies, model, previous, resolveRemoteDependencies);
delegatingClassLoader.add(previous);
// Path libFolder = projectRoot.resolve("lib");
// loadDependencies(libFolder, delegatingClassLoader);
EclipsePluginClassloader pluginClassloader = new EclipsePluginClassloader(delegatingClassLoader, projectRoot);
// pluginClassloader.dumpStructure(0);
ResourceLoader resourceLoader = new ResourceLoader() {
@Override
public InputStream load(String name) {
try {
return Files.newInputStream(pluginFolder.resolve(name));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
};
SPluginBundle sPluginBundle = new SPluginBundle();
if (model.getOrganization() == null) {
throw new PluginException("Plugis are required to have an organization in the pom.xml file");
}
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, true);
Path icon = projectRoot.resolve("icon.png");
if (Files.exists(icon)) {
byte[] iconBytes = Files.readAllBytes(icon);
sPluginBundleVersion.setIcon(iconBytes);
}
sPluginBundle.setInstalledVersion(sPluginBundleVersion);
return loadPlugins(pluginBundleVersionIdentifier, resourceLoader, pluginClassloader, projectRoot.toUri(), projectRoot.resolve("target/classes").toString(), pluginDescriptor, PluginSourceType.ECLIPSE_PROJECT, bimServerDependencies, sPluginBundle, sPluginBundleVersion);
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class MavenPluginLocation method createMavenVersion.
private MavenPluginVersion createMavenVersion(Version version) throws ArtifactDescriptorException, FileNotFoundException, IOException, ArtifactResolutionException, XmlPullParserException {
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
descriptorRequest.setArtifact(versionArtifact);
descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
ArtifactDescriptorResult descriptorResult;
descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
try {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(descriptorResult.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
File pomFile = resolveArtifact.getArtifact().getFile();
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try (FileReader fileReader = new FileReader(pomFile)) {
Model model = mavenreader.read(fileReader);
mavenPluginVersion.setModel(model);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
}
return mavenPluginVersion;
}
Aggregations