Search in sources :

Example 1 with MavenPluginVersion

use of org.bimserver.plugins.MavenPluginVersion in project BIMserver by opensourceBIM.

the class PluginBundleDatabaseAction method processMavenPluginLocation.

public SPluginBundle processMavenPluginLocation(MavenPluginLocation mavenPluginLocation, boolean strictVersionChecking, ArtifactVersion bimserverVersion) {
    SPluginBundle pluginBundle = new SPluginBundle();
    boolean usefulBundle = false;
    for (PluginVersion pluginVersion : mavenPluginLocation.getAllVersions()) {
        if (pluginVersion instanceof MavenPluginVersion) {
            SPluginBundleVersion sPluginBundleVersion = new SPluginBundleVersion();
            boolean useful = true;
            MavenPluginVersion mavenPluginVersion = (MavenPluginVersion) pluginVersion;
            for (MavenDependency mavenDependency : mavenPluginVersion.getDependencies()) {
                if (mavenDependency.getArtifact().getGroupId().equals("org.opensourcebim")) {
                    String artifactId = mavenDependency.getArtifact().getArtifactId();
                    // for the plugin, it's version has to be ok
                    if (artifactId.equals("shared") || artifactId.equals("pluginbase")) {
                        VersionRange versionRange = VersionRange.createFromVersion(mavenDependency.getArtifact().getVersion());
                        if (bimserverVersion != null && versionRange.containsVersion(bimserverVersion)) {
                        } else {
                            sPluginBundleVersion.setMismatch(true);
                            if (strictVersionChecking) {
                                useful = false;
                                LOGGER.info("Skipping version " + mavenPluginVersion.getArtifact().getVersion() + " or artifact " + mavenPluginVersion.getArtifact().getArtifactId());
                            }
                        }
                    }
                }
            }
            if (useful) {
                usefulBundle = true;
                sPluginBundleVersion.setName(mavenPluginVersion.getModel().getName());
                sPluginBundleVersion.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
                sPluginBundleVersion.setArtifactId(mavenPluginLocation.getArtifactId());
                sPluginBundleVersion.setGroupId(mavenPluginLocation.getGroupId());
                try {
                    sPluginBundleVersion.setRepository(mavenPluginLocation.getRepository(mavenPluginVersion.getVersion().toString()));
                } catch (ArtifactResolutionException e) {
                    LOGGER.error("", e);
                }
                sPluginBundleVersion.setType(SPluginBundleType.MAVEN);
                sPluginBundleVersion.setVersion(mavenPluginVersion.getVersion().toString());
                sPluginBundleVersion.setDescription(mavenPluginVersion.getModel().getDescription());
                pluginBundle.setName(mavenPluginVersion.getModel().getName());
                pluginBundle.setOrganization(mavenPluginVersion.getModel().getOrganization().getName());
                pluginBundle.setLatestVersion(sPluginBundleVersion);
                pluginBundle.getAvailableVersions().add(sPluginBundleVersion);
                try {
                    sPluginBundleVersion.setIcon(mavenPluginLocation.getVersionIcon(mavenPluginVersion.getVersion().toString()));
                } catch (ArtifactResolutionException e) {
                // This is not important
                } catch (IOException e) {
                    LOGGER.error("", e);
                }
                try {
                    GregorianCalendar date = mavenPluginLocation.getVersionDate(mavenPluginVersion.getVersion().toString());
                    if (date != null) {
                        sPluginBundleVersion.setDate(date.getTime());
                    }
                // byte[] bytes = Files.readAllBytes(date);
                // Properties properties = new Properties();
                // properties.load(new ByteArrayInputStream(bytes));
                // String buildDateString = properties.getProperty("build.date");
                // 
                // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                // try {
                // } catch (ParseException e) {
                // LOGGER.error("Invalid date format for plugin " + mavenPluginVersion.getModel().getName() + ": '" + buildDateString + "'");
                // }
                } catch (ArtifactResolutionException e) {
                // Not a problem
                } catch (Exception e) {
                    LOGGER.error("", e);
                }
            }
        }
    }
    if (usefulBundle) {
        return pluginBundle;
    }
    return null;
}
Also used : SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenPluginVersion(org.bimserver.plugins.MavenPluginVersion) PluginVersion(org.bimserver.plugins.PluginVersion) MavenPluginVersion(org.bimserver.plugins.MavenPluginVersion) SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) GregorianCalendar(java.util.GregorianCalendar) VersionRange(org.apache.maven.artifact.versioning.VersionRange) IOException(java.io.IOException) IOException(java.io.IOException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenDependency(org.bimserver.plugins.MavenDependency)

Aggregations

IOException (java.io.IOException)1 GregorianCalendar (java.util.GregorianCalendar)1 VersionRange (org.apache.maven.artifact.versioning.VersionRange)1 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)1 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)1 MavenDependency (org.bimserver.plugins.MavenDependency)1 MavenPluginVersion (org.bimserver.plugins.MavenPluginVersion)1 PluginVersion (org.bimserver.plugins.PluginVersion)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1