Search in sources :

Example 6 with SPluginBundleVersion

use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.

the class PluginManager method createPluginBundleVersionFromMavenModel.

private SPluginBundleVersion createPluginBundleVersionFromMavenModel(Model model, boolean isLocalDev) {
    SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
    sPluginBundleVersion.setType(isLocalDev ? SPluginBundleType.LOCAL_DEV : SPluginBundleType.MAVEN);
    sPluginBundleVersion.setGroupId(model.getGroupId());
    sPluginBundleVersion.setArtifactId(model.getArtifactId());
    sPluginBundleVersion.setVersion(model.getVersion());
    sPluginBundleVersion.setDescription(model.getDescription());
    sPluginBundleVersion.setRepository("local");
    // TODO
    sPluginBundleVersion.setMismatch(false);
    sPluginBundleVersion.setOrganization(model.getOrganization().getName());
    sPluginBundleVersion.setName(model.getName());
    return sPluginBundleVersion;
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion)

Example 7 with SPluginBundleVersion

use of org.bimserver.interfaces.objects.SPluginBundleVersion 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);
    }
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ZipEntry(java.util.zip.ZipEntry) PluginException(org.bimserver.shared.exceptions.PluginException) Model(org.apache.maven.model.Model) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile)

Example 8 with SPluginBundleVersion

use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getPluginBundleVersion.

public SPluginBundleVersion getPluginBundleVersion(String version) {
    try {
        Path pomFile = getVersionPom(version);
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = null;
        try (FileReader fileReader = new FileReader(pomFile.toFile())) {
            model = mavenreader.read(fileReader);
        }
        SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
        sPluginBundleVersion.setOrganization(model.getOrganization().getName());
        sPluginBundleVersion.setName(model.getName());
        sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
        sPluginBundleVersion.setGroupId(groupId);
        sPluginBundleVersion.setArtifactId(artifactId);
        sPluginBundleVersion.setVersion(version);
        sPluginBundleVersion.setDescription(model.getDescription());
        sPluginBundleVersion.setRepository(defaultrepository);
        sPluginBundleVersion.setMismatch(false);
        try {
            sPluginBundleVersion.setIcon(getVersionIcon(version));
        } catch (ArtifactResolutionException e) {
        // Not a problem
        }
        try {
            GregorianCalendar date = getVersionDate(version);
            // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            if (date != null) {
                sPluginBundleVersion.setDate(date.getTime());
            }
        } catch (ArtifactResolutionException e) {
        // Not a problem
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        return sPluginBundleVersion;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Path(java.nio.file.Path) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Model(org.apache.maven.model.Model) GregorianCalendar(java.util.GregorianCalendar) FileNotFoundException(java.io.FileNotFoundException) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ParseException(java.text.ParseException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with SPluginBundleVersion

use of org.bimserver.interfaces.objects.SPluginBundleVersion in project BIMserver by opensourceBIM.

the class LocalMavenPluginBundle method getPluginBundleVersion.

@Override
public SPluginBundleVersion getPluginBundleVersion() {
    SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
    sPluginBundleVersion.setType(SPluginBundleType.LOCAL);
    sPluginBundleVersion.setGroupId(model.getGroupId());
    sPluginBundleVersion.setArtifactId(model.getArtifactId());
    sPluginBundleVersion.setVersion(model.getVersion());
    sPluginBundleVersion.setDescription(model.getDescription());
    sPluginBundleVersion.setRepository("local");
    // TODO
    sPluginBundleVersion.setMismatch(false);
    sPluginBundleVersion.setOrganization(model.getOrganization().getName());
    sPluginBundleVersion.setName(model.getName());
    return sPluginBundleVersion;
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion)

Aggregations

SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)9 IOException (java.io.IOException)5 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)4 Path (java.nio.file.Path)3 GregorianCalendar (java.util.GregorianCalendar)3 Model (org.apache.maven.model.Model)3 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)3 FileReader (java.io.FileReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 PluginBundle (org.bimserver.plugins.PluginBundle)2 PluginException (org.bimserver.shared.exceptions.PluginException)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1 SecureRandom (java.security.SecureRandom)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1