Example usage for org.apache.maven.project MavenProject getProperties

List of usage examples for org.apache.maven.project MavenProject getProperties

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getProperties.

Prototype

public Properties getProperties() 

Source Link

Usage

From source file:org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.java

License:Open Source License

public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;/*ww w.  j a v  a 2  s  .co m*/
    }

    // generic Eclipse/OSGi metadata

    dr.setupProject(session, project);

    // p2 metadata

    Properties properties = new Properties();
    properties.putAll(project.getProperties());
    properties.putAll(session.getSystemProperties()); // session wins
    properties.putAll(session.getUserProperties());
    project.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

    TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session,
            project);
    project.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, configuration);

    TargetPlatformResolver resolver = targetPlatformResolverLocator.lookupPlatformResolver(project);

    resolver.setupProjects(session, project, reactorProject);
}

From source file:org.eclipse.tycho.core.resolver.DefaultTychoResolver.java

License:Open Source License

@Override
public void setupProject(MavenSession session, MavenProject project, ReactorProject reactorProject) {
    AbstractTychoProject dr = (AbstractTychoProject) projectTypes.get(project.getPackaging());
    if (dr == null) {
        return;//from   w  w  w . ja  v a 2  s .co m
    }

    // skip if setup was already done
    if (project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES) != null) {
        return;
    }

    // generic Eclipse/OSGi metadata

    dr.setupProject(session, project);

    // p2 metadata

    Properties properties = new Properties();
    properties.putAll(project.getProperties());
    properties.putAll(session.getSystemProperties()); // session wins
    properties.putAll(session.getUserProperties());
    project.setContextValue(TychoConstants.CTX_MERGED_PROPERTIES, properties);

    setTychoEnvironmentProperties(properties, project);

    TargetPlatformConfiguration configuration = configurationReader.getTargetPlatformConfiguration(session,
            project);
    project.setContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION, configuration);

    ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger,
            !configuration.isResolveWithEEConstraints());
    dr.readExecutionEnvironmentConfiguration(project, eeConfiguration);
    project.setContextValue(TychoConstants.CTX_EXECUTION_ENVIRONMENT_CONFIGURATION, eeConfiguration);

    DependencyResolver resolver = dependencyResolverLocator.lookupDependencyResolver(project);
    resolver.setupProjects(session, project, reactorProject);
}

From source file:org.eclipse.tycho.core.resolver.DefaultTychoResolver.java

License:Open Source License

protected void setTychoEnvironmentProperties(Properties properties, MavenProject project) {
    String arch = PlatformPropertiesUtils.getArch(properties);
    String os = PlatformPropertiesUtils.getOS(properties);
    String ws = PlatformPropertiesUtils.getWS(properties);
    project.getProperties().put(TYCHO_ENV_OSGI_WS, ws);
    project.getProperties().put(TYCHO_ENV_OSGI_OS, os);
    project.getProperties().put(TYCHO_ENV_OSGI_ARCH, arch);
}

From source file:org.eclipse.tycho.packaging.sourceref.SourceReferenceComputer.java

License:Open Source License

public void addSourceReferenceHeader(Manifest manifest, SourceReferences sourceRefsConfiguration,
        MavenProject project) throws MojoExecutionException {
    if (!sourceRefsConfiguration.shouldGenerate()) {
        return;/* ww  w .j a  v a  2 s. co  m*/
    }
    if (sourceRefsConfiguration.getCustomValue() != null) {
        addSourceReferencesHeader(manifest, sourceRefsConfiguration.getCustomValue());
        return;
    }
    ScmUrl scmUrl = new ScmUrl(project.getProperties());
    final String providerHint = scmUrl.getType();
    SourceReferencesProvider provider = providerMap.get(providerHint);
    if (provider == null) {
        throw new MojoExecutionException(
                "No source references provider for SCM type '" + providerHint + "' registered.");
    }
    addSourceReferencesHeader(manifest, provider.getSourceReferencesHeader(project, scmUrl));
}

From source file:org.eclipse.tycho.plugins.p2.publisher.PublishProductMojo.java

License:Open Source License

protected Interpolator newInterpolator() {
    final MavenProject mavenProject = getProject();
    final MavenSession mavenSession = getSession();
    final Properties baseProps = new Properties();
    baseProps.putAll(mavenProject.getProperties());
    baseProps.putAll(mavenSession.getSystemProperties());
    baseProps.putAll(mavenSession.getUserProperties());

    final Settings settings = mavenSession.getSettings();

    // roughly match resources plugin behaviour

    final StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new PrefixedObjectValueSource("project", mavenProject));
    interpolator.addValueSource(new PrefixedObjectValueSource("settings", settings));
    interpolator// w w  w. jav a  2s.  co  m
            .addValueSource(new SingleResponseValueSource("localRepository", settings.getLocalRepository()));
    interpolator.addValueSource(new ValueSource() {
        public Object getValue(String expression) {
            return baseProps.getProperty(expression);
        }

        public void clearFeedback() {
        }

        @SuppressWarnings("rawtypes")
        public List getFeedback() {
            return Collections.EMPTY_LIST;
        }
    });
    return interpolator;
}

From source file:org.eclipse.virgo.ide.bundlor.internal.core.maven.MavenPropertiesSource.java

License:Open Source License

public Properties getProperties() {
    try {/*from ww  w .ja  va2  s.  co  m*/
        IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry();
        IMavenProjectFacade facade = registry.create(this.project, new NullProgressMonitor());
        if (facade != null) {
            MavenProject mavenProj = facade.getMavenProject(new NullProgressMonitor());
            Properties props = mavenProj.getProperties();

            // add in some special maven properties
            addPropertyIfNotNull(props, "project.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.groupId", mavenProj.getGroupId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.description", mavenProj.getDescription()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.name", mavenProj.getName()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "project.version", mavenProj.getVersion()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.artifactId", mavenProj.getArtifactId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.groupId", mavenProj.getGroupId()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.description", mavenProj.getDescription()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.name", mavenProj.getName()); //$NON-NLS-1$
            addPropertyIfNotNull(props, "pom.version", mavenProj.getVersion()); //$NON-NLS-1$

            return props;
        }
    } catch (CoreException e) {
        // this exception will be reported later on as the properties can't be reported.
    }
    return EMPTY_STANDARD;
}

From source file:org.fluidity.foundation.impl.BundleJarManifest.java

License:Apache License

public SecurityPolicy processManifest(final MavenProject project, final Attributes attributes,
        final SecurityPolicy policy, final Logger log, final Dependencies dependencies)
        throws MojoExecutionException {
    dependencies.attribute(BUNDLE_CLASSPATH, ",");

    addEntry(attributes, BUNDLE_MANIFESTVERSION, "2");
    addEntry(attributes, BUNDLE_NAME, project::getName);
    addEntry(attributes, BUNDLE_SYMBOLICNAME, project::getArtifactId);
    addEntry(attributes, BUNDLE_VERSION, project::getVersion);
    addEntry(attributes, BUNDLE_DESCRIPTION, project::getDescription);
    addEntry(attributes, BUNDLE_DOCURL, project::getUrl);
    addEntry(attributes, BUNDLE_VENDOR, () -> {
        return project.getOrganization().getName();
    });/*from  ww w . j  a  va2s.c om*/
    addEntry(attributes, BUNDLE_COPYRIGHT, () -> {
        final String year = project.getInceptionYear();
        return year == null ? null
                : String.format("Copyright %s (c) %s. All rights reserved.",
                        project.getOrganization().getName(), year);
    });
    addEntry(attributes, REQUIRE_CAPABILITY, () -> {

        // https://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
        final String[] version = System.getProperty("java.version").split("\\.");
        return String.format("osgi.ee;filter:=(&(osgi.ee=JavaSE)(version>=%s.%s))", version[0], version[1]);
    });

    final String version = attributes.getValue(BUNDLE_VERSION);

    if (version != null) {
        attributes.putValue(BUNDLE_VERSION, verify(version));
    } else {
        addEntry(attributes, BUNDLE_VERSION, DEFAULT_BUNDLE_VERSION);
    }

    final RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
    final List<String> prefixes = Collections.singletonList("project.");

    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    interpolator.addValueSource(new PrefixedPropertiesValueSource(prefixes, project.getProperties(), true));
    interpolator.addValueSource(new PrefixedObjectValueSource(prefixes, project.getModel(), true));

    final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(prefixes, true);

    interpolator.setCacheAnswers(true);
    interpolator.setReusePatterns(true);

    interpolator.addPostProcessor((ignored, value) -> verify((String) value));

    try {
        interpolateHeaders(attributes, interpolator, interceptor, EXPORT_PACKAGE, IMPORT_PACKAGE,
                DYNAMICIMPORT_PACKAGE, FRAGMENT_HOST, REQUIRE_BUNDLE, BUNDLE_NATIVECODE);
    } catch (final InterpolationException e) {
        throw new IllegalStateException(e);
    }

    final Collection<Artifact> artifacts = dependencies.compiler();

    // if embedding project dependencies, see if Fluid Tools composition is included and if so, add a bundle activator to bootstrap the system.
    if (!artifacts.isEmpty()) {
        try {

            // create a class loader that sees the project's compile-time dependencies
            final Set<URL> urls = new HashSet<>();

            final String skippedId = project.getArtifact().getId();
            for (final Artifact dependency : artifacts) {

                // we don't need the project artifact and don't want to prevent the caller from overwriting it by locking the file...
                if (!skippedId.equals(dependency.getId())) {
                    urls.add(dependency.getFile().toURI().toURL());
                }
            }

            final Method method = Methods.get(BootstrapDiscovery.class, BootstrapDiscovery::activator)[0];

            urls.add((Archives.containing(BootstrapDiscovery.class)));
            urls.add((Archives.containing(BootstrapDiscoveryImpl.class)));
            urls.add((Archives.containing(ComponentContainer.class)));

            final String activator = isolate(null, urls, BootstrapDiscoveryImpl.class, method);

            if (activator != null) {
                addEntry(attributes, BUNDLE_ACTIVATOR, activator);
            }

            if (log.active()) {
                final String value = attributes.getValue(BUNDLE_ACTIVATOR);
                log.detail("Bundle activator: %s", value == null ? "none"
                        : value.equals(BundleBootstrap.class.getName()) ? "built in" : value);
            }
        } catch (final ClassNotFoundException e) {
            // that's OK
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }
    }

    return new OsgiLocalPermissions(policy, artifacts, attributes.getValue(DYNAMICIMPORT_PACKAGE),
            attributes.getValue(IMPORT_PACKAGE), attributes.getValue(EXPORT_PACKAGE));
}

From source file:org.gephi.maven.BuildMetadata.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String gephiVersion = (String) project.getProperties().get("gephi.version");
    if (gephiVersion == null) {
        throw new MojoExecutionException("The 'gephi.version' property should be defined");
    }/*w w  w. j a va  2 s.  c  om*/
    getLog().debug("Building metadata for 'gephi.version=" + gephiVersion + "'");

    if (reactorProjects != null && reactorProjects.size() > 0) {
        getLog().debug("Found " + reactorProjects.size() + " projects in reactor");
        List<MavenProject> modules = new ArrayList<MavenProject>();
        for (MavenProject proj : reactorProjects) {
            if (proj.getPackaging().equals("nbm")) {
                String gephiVersionModule = proj.getProperties().getProperty("gephi.version");

                if (gephiVersionModule.equals(gephiVersion)) {
                    getLog().debug("Found 'nbm' project '" + proj.getName() + "' with artifactId="
                            + proj.getArtifactId() + " and groupId=" + proj.getGroupId());
                    modules.add(proj);
                } else {
                    getLog().debug("Ignored project '" + proj.getName() + "' based on 'gephi.version' value '"
                            + gephiVersionModule + "'");
                }
            }
        }

        ManifestUtils manifestUtils = new ManifestUtils(sourceManifestFile, getLog());

        // Get all modules with dependencies
        Map<MavenProject, List<MavenProject>> tree = ModuleUtils.getModulesTree(modules, getLog());

        //Download previous file
        File pluginsJsonFile = new File(outputDirectory, "plugins.json");
        try {
            URL url = new URL(metadataUrl + "plugins.json");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
            connection.connect();
            InputStream stream = connection.getInputStream();
            ReadableByteChannel rbc = Channels.newChannel(stream);
            FileOutputStream fos = new FileOutputStream(pluginsJsonFile);
            long read = fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            rbc.close();
            stream.close();
            getLog().debug("Read " + read + "bytes from url '" + url + "' and write to '"
                    + pluginsJsonFile.getAbsolutePath() + "'");
        } catch (Exception e) {
            throw new MojoExecutionException("Error while downloading previous 'plugins.json'", e);
        }

        // Init json
        PluginsMetadata pluginsMetadata;
        Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
        if (pluginsJsonFile.exists()) {
            try {
                FileReader reader = new FileReader(pluginsJsonFile);
                pluginsMetadata = gson.fromJson(reader, PluginsMetadata.class);
                reader.close();
                getLog().debug("Read previous plugins.json file");
            } catch (JsonSyntaxException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            } catch (JsonIOException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            } catch (IOException e) {
                throw new MojoExecutionException("Error while reading previous 'plugins.json'", e);
            }
        } else {
            pluginsMetadata = new PluginsMetadata();
            pluginsMetadata.plugins = new ArrayList<PluginMetadata>();
            getLog().debug("Create plugins.json");
        }

        // Build metadata
        for (Map.Entry<MavenProject, List<MavenProject>> entry : tree.entrySet()) {
            MavenProject topPlugin = entry.getKey();
            PluginMetadata pm = new PluginMetadata();
            pm.id = topPlugin.getArtifactId();

            // Find previous
            boolean foundPrevious = false;
            for (PluginMetadata oldPm : pluginsMetadata.plugins) {
                if (oldPm.id.equals(pm.id)) {
                    pm = oldPm;
                    foundPrevious = true;
                    getLog().debug("Found matching plugin id=" + pm.id + " in previous plugins.json");
                    break;
                }
            }

            manifestUtils.readManifestMetadata(topPlugin, pm);
            pm.license = MetadataUtils.getLicenseName(topPlugin);
            pm.authors = MetadataUtils.getAuthors(topPlugin);
            pm.last_update = dateFormat.format(new Date());
            pm.readme = MetadataUtils.getReadme(topPlugin, getLog());
            pm.images = ScreenshotUtils.copyScreenshots(topPlugin,
                    new File(outputDirectory, "imgs" + File.separator + pm.id), "imgs" + "/" + pm.id + "/",
                    getLog());
            pm.homepage = MetadataUtils.getHomepage(topPlugin);
            pm.sourcecode = MetadataUtils.getSourceCode(topPlugin, getLog());

            if (pm.versions == null) {
                pm.versions = new HashMap<String, Version>();
            }
            Version v = new Version();
            v.last_update = dateFormat.format(new Date());
            v.url = gephiVersion + "/" + ModuleUtils.getModuleDownloadPath(entry.getKey(), entry.getValue(),
                    new File(outputDirectory, gephiVersion), getLog());
            pm.versions.put(gephiVersion, v);

            if (!foundPrevious) {
                pluginsMetadata.plugins.add(pm);
            }
        }

        String json = gson.toJson(pluginsMetadata);

        // Write json file
        try {
            FileWriter writer = new FileWriter(pluginsJsonFile);
            writer.append(json);
            writer.close();
        } catch (IOException ex) {
            throw new MojoExecutionException("Error while writing plugins.json file", ex);
        }
    } else {
        throw new MojoExecutionException("The project should be a reactor project");
    }
}

From source file:org.gephi.maven.CreateAutoUpdate.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String gephiVersion = (String) project.getProperties().get("gephi.version");
    if (gephiVersion == null) {
        throw new MojoExecutionException("The 'gephi.version' property should be defined");
    }//from  w  w w .  ja v a 2  s  .  c  om

    File outputFolder = new File(outputDirectory, gephiVersion);
    if (outputFolder.mkdirs()) {
        getLog().debug("Folder '" + outputFolder.getAbsolutePath() + "' created.");
    }

    if (reactorProjects != null && reactorProjects.size() > 0) {
        Project antProject = registerNbmAntTasks();

        for (MavenProject proj : reactorProjects) {
            if (proj.getPackaging().equals("nbm")) {
                File moduleDir = proj.getFile().getParentFile();
                if (moduleDir != null && moduleDir.exists()) {
                    File targetDir = new File(moduleDir, "target");
                    if (targetDir.exists()) {
                        String gephiVersionModule = proj.getProperties().getProperty("gephi.version");
                        if (gephiVersionModule == null) {
                            throw new MojoExecutionException(
                                    "The 'gephi.version' property should be defined in project '"
                                            + proj.getName() + "'");
                        }
                        if (gephiVersionModule.equals(gephiVersion)) {
                            File[] nbmsFiles = targetDir.listFiles(new FilenameFilter() {
                                @Override
                                public boolean accept(File dir, String name) {
                                    return !name.startsWith(".") && name.endsWith(".nbm");
                                }
                            });
                            for (File nbmFile : nbmsFiles) {
                                try {
                                    FileUtils.copyFileToDirectory(nbmFile, outputFolder);
                                } catch (IOException ex) {
                                    getLog().error(
                                            "Error while copying nbm file '" + nbmFile.getAbsolutePath() + "'",
                                            ex);
                                }
                                getLog().info("Copying  '" + nbmFile + "' to '" + outputFolder.getAbsolutePath()
                                        + "'");
                            }
                        } else {
                            getLog().warn("The NBM of module '" + proj.getName()
                                    + "' has been ignored because its 'gephi.version' is '" + gephiVersionModule
                                    + "' while '" + gephiVersion + "' is expected");
                        }
                    } else {
                        getLog().error(
                                "The module target dir for project '" + proj.getName() + "' doesn't exists");
                    }
                } else {
                    getLog().error("The module dir for project '" + proj.getName() + "' doesn't exists");
                }
            }
        }

        // Create updates.xml
        String fileName = "updates.xml";
        MakeUpdateDesc descTask = (MakeUpdateDesc) antProject.createTask("updatedist");
        File xmlFile = new File(outputFolder, fileName);
        descTask.setDesc(xmlFile);
        FileSet fs = new FileSet();
        fs.setDir(outputFolder);
        fs.createInclude().setName("**/*.nbm");
        descTask.addFileset(fs);
        try {
            descTask.execute();
        } catch (BuildException ex) {
            throw new MojoExecutionException("Cannot create autoupdate site xml file", ex);
        }
        getLog().info("Generated autoupdate site content at " + outputFolder.getAbsolutePath());

        // Create compressed version of updates.xml
        try {
            GZipArchiver gz = new GZipArchiver();
            gz.addFile(xmlFile, fileName);
            File gzipped = new File(outputFolder, fileName + ".gz");
            gz.setDestFile(gzipped);
            gz.createArchive();
        } catch (ArchiverException ex) {
            throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
        } catch (IOException ex) {
            throw new MojoExecutionException("Cannot create gzipped version of the update site xml file.", ex);
        }
        getLog().info("Generated compressed autoupdate site content at " + outputFolder.getAbsolutePath());
    } else {
        throw new MojoExecutionException("This should be executed on the reactor project");
    }
}

From source file:org.gephi.maven.Validate.java

License:Apache License

private void checkGephiVersion(MavenProject moduleProject) throws MojoExecutionException {
    String moduleVersion = moduleProject.getProperties().getProperty("gephi.version");
    String projectVersion = project.getProperties().getProperty("gephi.version");
    if (!moduleVersion.equals(projectVersion)) {
        getLog().warn("The project '" + moduleProject.getName() + "' depends on Gephi version '" + moduleVersion
                + "' but '" + projectVersion + "' is expected, it will be ignored");
    }//from  w  ww  .ja  v  a 2  s.c o m
}