Example usage for org.apache.maven.execution MavenSession getStartTime

List of usage examples for org.apache.maven.execution MavenSession getStartTime

Introduction

In this page you can find the example usage for org.apache.maven.execution MavenSession getStartTime.

Prototype

public Date getStartTime() 

Source Link

Usage

From source file:org.sourcepit.b2.p2.MavenDependenciesSiteGenerator.java

License:Apache License

public void preInterpolation(AbstractModule module, final PropertiesSource moduleProperties) {
    final MavenSession session = legacySupport.getSession();
    final MavenProject project = session.getCurrentProject();

    final List<Dependency> dependencies = new ArrayList<Dependency>(filter(project.getDependencies(), JARS));
    if (!dependencies.isEmpty()) {
        final IInterpolationLayout layout = layoutManager.getLayout(module.getLayoutId());
        final File siteDir = new File(layout.pathOfMetaDataFile(module, "maven-dependencies"));

        final String repositoryName = "maven-dependencies@" + project.getArtifactId();
        final List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
        final ArtifactRepository localRepository = session.getLocalRepository();

        final Date startTime = session.getStartTime();

        final String pattern = moduleProperties.get("osgifier.updateSiteBundles");
        final PathMatcher bundleMatcher = pattern == null ? null : PathMatcher.parsePackagePatterns(pattern);

        BundleSelector bundleSelector = new AbstractBundleTreeSelector() {
            @Override//from w  w  w  . j av a  2s  . com
            public Collection<BundleCandidate> selectRootBundles(OsgifierContext bundleContext) {
                final DependencyModel dependencyModel = bundleContext.getExtension(DependencyModel.class);

                final Map<ArtifactKey, BundleCandidate> artifactKeyToBundle = new HashMap<ArtifactKey, BundleCandidate>();
                for (BundleCandidate bundle : bundleContext.getBundles()) {
                    artifactKeyToBundle.put(getArtifactKey(bundle), bundle);
                }

                final List<BundleCandidate> rootBundles = new ArrayList<BundleCandidate>();
                for (MavenArtifact artifact : dependencyModel.getRootArtifacts()) {
                    final BundleCandidate rootBundle = artifactKeyToBundle.get(artifact.getArtifactKey());
                    if (rootBundle != null && select(rootBundle)) {
                        rootBundles.add(rootBundle);
                    }
                }
                return rootBundles;
            }

            private ArtifactKey getArtifactKey(BundleCandidate bundle) {
                return bundle.getExtension(MavenArtifact.class).getArtifactKey();
            }

            @Override
            public boolean select(Stack<BundleCandidate> path, BundleReference reference) {
                return !reference.isOptional() && super.select(path, reference);
            }

            @Override
            protected boolean select(BundleCandidate bundle) {
                return bundleMatcher == null || bundleMatcher.isMatch(bundle.getSymbolicName());
            }
        };

        final OsgifierContext bundleContext = updateSiteGenerator.generateUpdateSite(siteDir, dependencies,
                true, remoteRepositories, localRepository, repositoryName, moduleProperties, startTime,
                bundleSelector);

        try {
            module.setAnnotationData("b2.mavenDependencies", "repositoryURL",
                    siteDir.toURI().toURL().toExternalForm());
        } catch (MalformedURLException e) {
            throw pipe(e);
        }
        module.setAnnotationData("b2.mavenDependencies", "repositoryName", repositoryName);

        final Collection<BundleCandidate> selectedBundles = new LinkedHashSet<BundleCandidate>();
        selectBundles(selectedBundles, bundleContext, bundleSelector);
        interpolatePlugins(module, moduleProperties, selectedBundles);
    }
}