use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project asterixdb by apache.
the class SupplementalModelHelper method getSupplement.
protected static Model getSupplement(Log log, Xpp3Dom supplementModelXml) throws MojoExecutionException {
MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = null;
try {
model = modelReader.read(new StringReader(supplementModelXml.toString()));
String groupId = model.getGroupId();
String artifactId = model.getArtifactId();
if (groupId == null || "".equals(groupId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <groupId> element be present.");
}
if (artifactId == null || "".equals(artifactId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <artifactId> element be present.");
}
} catch (IOException e) {
log.warn("Unable to read supplemental XML: " + e.getMessage(), e);
} catch (XmlPullParserException e) {
log.warn("Unable to parse supplemental XML: " + e.getMessage(), e);
}
return model;
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class PluginManager method loadJavaProject.
public PluginBundle loadJavaProject(Path projectRoot, Path pomFile, Path pluginFolder, PluginDescriptor pluginDescriptor) 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);
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();
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 PluginManager 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 (JarInputStream jarInputStream = new JarInputStream(mavenPluginBundle.getJarInputStream())) {
JarEntry nextJarEntry = jarInputStream.getNextJarEntry();
while (nextJarEntry != null) {
if (nextJarEntry.getName().equals("plugin/plugin.xml")) {
// Install all plugins
PluginDescriptor pluginDescriptor = getPluginDescriptor(new FakeClosingInputStream(jarInputStream));
plugins = new ArrayList<>();
processPluginDescriptor(pluginDescriptor, plugins);
for (SPluginInformation info : plugins) {
info.setInstallForAllUsers(true);
info.setInstallForNewUsers(true);
}
break;
}
nextJarEntry = jarInputStream.getNextJarEntry();
}
}
}
DelegatingClassLoader delegatingClassLoader = new DelegatingClassLoader(getClass().getClassLoader());
for (org.apache.maven.model.Dependency dependency : model.getDependencies()) {
if (dependency.getGroupId().equals("org.opensourcebim") && (dependency.getArtifactId().equals("shared") || dependency.getArtifactId().equals("pluginbase"))) {
// 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(mavenPluginBundle.getVersion());
if (versionRange.containsVersion(artifactVersion)) {
// OK
} else {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + mavenPluginBundle.getVersion() + ") does not comply to the required version (" + dependency.getVersion() + ")");
}
} else {
LOGGER.info("Skipping strict dependency checking for dependency " + dependency.getArtifactId());
}
} else {
try {
MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependency.getGroupId(), dependency.getArtifactId());
Path depJarFile = mavenPluginLocation.getVersionJar(dependency.getVersion());
FileJarClassLoader jarClassLoader = new FileJarClassLoader(this, delegatingClassLoader, depJarFile);
jarClassLoaders.add(jarClassLoader);
delegatingClassLoader.add(jarClassLoader);
} catch (Exception e) {
throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed");
}
}
}
}
Path target = pluginsDir.resolve(pluginBundleVersionIdentifier.getFileName());
if (Files.exists(target)) {
throw new PluginException("This plugin has already been installed " + target.getFileName().toString());
}
Files.copy(mavenPluginBundle.getJarInputStream(), target);
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 PluginManager method extractPluginBundleFromJar.
// public void loadAllPluginsFromDirectoryOfJars(Path directory) throws
// PluginException, IOException {
// LOGGER.debug("Loading all plugins from " + directory.toString());
// if (!Files.isDirectory(directory)) {
// throw new PluginException("No directory: " + directory.toString());
// }
// for (Path file : PathUtils.list(directory)) {
// if (file.getFileName().toString().toLowerCase().endsWith(".jar")) {
// try {
// PluginBundleVersionIdentifier pluginBundleVersionIdentifier =
// PluginBundleVersionIdentifier.fromFileName(file.getFileName().toString());
//
// loadPluginsFromJar(pluginBundleVersionIdentifier, file,
// extractPluginBundleFromJar(file),
// extractPluginBundleVersionFromJar(file));
// } catch (PluginException e) {
// LOGGER.error("", e);
// }
// }
// }
// }
public SPluginBundle extractPluginBundleFromJar(Path jarFilePath) throws PluginException {
String filename = jarFilePath.getFileName().toString();
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
String pomLocation = "META-INF/maven/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getGroupId() + "/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getArtifactId() + "/" + "pom.xml";
ZipEntry pomEntry = jarFile.getEntry(pomLocation);
if (pomEntry == null) {
throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString() + ", " + pomLocation);
}
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
SPluginBundle sPluginBundle = new SPluginBundle();
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
return sPluginBundle;
} catch (IOException e) {
throw new PluginException(e);
} catch (XmlPullParserException e) {
throw new PluginException(e);
}
}
use of org.eclipse.ceylon.aether.apache.maven.model.io.xpp3.MavenXpp3Reader in project BIMserver by opensourceBIM.
the class PluginManager method extractPluginBundleVersionFromJar.
public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException {
String filename = jarFilePath.getFileName().toString();
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml");
if (pomEntry == null) {
throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString());
}
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal);
return sPluginBundleVersion;
} catch (IOException e) {
throw new PluginException(e);
} catch (XmlPullParserException e) {
throw new PluginException(e);
}
}
Aggregations