List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:org.sonatype.nexus.plugin.deploy.AbstractDeployMojo.java
License:Open Source License
protected File getStagingDirectory() { if (altStagingDirectory != null) { return altStagingDirectory; } else {/* ww w . j a v a 2 s . c om*/ final MavenProject firstWithThisMojo = MojoExecution.getFirstProjectWithMojoInExecution(mavenSession, pluginGroupId, pluginArtifactId); if (firstWithThisMojo != null) { // the target of 1st project having this mojo defined return new File(firstWithThisMojo.getBasedir().getAbsolutePath(), "target/nexus-staging"); } else { // top level (invocation place) return new File(getMavenSession().getExecutionRootDirectory() + "/target/nexus-staging"); } } }
From source file:org.sonatype.tycho.m2e.felix.internal.MavenBundlePluginConfigurator.java
License:Open Source License
@Override public AbstractBuildParticipant getBuildParticipant(IMavenProjectFacade projectFacade, final MojoExecution execution, IPluginExecutionMetadata executionMetadata) { return new AbstractBuildParticipant() { @Override//from w w w . j a v a 2s . c o m public Set<IProject> build(int kind, IProgressMonitor monitor) throws Exception { BuildContext buildContext = getBuildContext(); IMavenProjectFacade facade = getMavenProjectFacade(); IProject project = facade.getProject(); MavenProject mavenProject = facade.getMavenProject(monitor); @SuppressWarnings("unchecked") Map<String, String> instructions = maven.getMojoParameterValue(mavenProject, execution, "instructions", Map.class, monitor); MojoExecution _execution = amendMojoExecution(mavenProject, execution, instructions); IFile manifest = getManifestFile(facade, _execution, monitor); // regenerate bundle manifest if any of the following is true // - full workspace build // - PROP_FORCE_GENERATE project session property is set (see the comment below) // - any of included bnd files changed boolean generate = IncrementalProjectBuilder.FULL_BUILD == kind; // the property is set by OsgiBundleProjectConfigurator.mavenProjectChanged is a workaround for // m2e design limitation, which does not allow project configurators trigger resource deltas // visible to build participants. See comment in OsgiBundleProjectConfigurator.mavenProjectChanged generate = generate || Boolean.parseBoolean((String) project.getSessionProperty(PROP_FORCE_GENERATE)); // reset FORCE flag so we don't regenerate forever project.setSessionProperty(PROP_FORCE_GENERATE, null); generate = generate || isIncludeBndFileChange(buildContext, instructions); if (!generate) { return null; } maven.execute(mavenProject, _execution, monitor); manifest.refreshLocal(IResource.DEPTH_INFINITE, monitor); // refresh parent? if (isDeclerativeServices(mavenProject.getBasedir(), instructions)) { IFolder outputFolder = getOutputFolder(monitor, facade, _execution); outputFolder.getFolder("OSGI-OPT").refreshLocal(IResource.DEPTH_INFINITE, monitor); outputFolder.getFolder("OSGI-INF").refreshLocal(IResource.DEPTH_INFINITE, monitor); } return null; } protected IFolder getOutputFolder(IProgressMonitor monitor, IMavenProjectFacade facade, MojoExecution _execution) throws CoreException { File outputDirectory = getParameterValue(facade.getMavenProject(), "outputDirectory", File.class, _execution, monitor); IPath outputPath = facade.getProjectRelativePath(outputDirectory.getAbsolutePath()); IFolder outputFolder = facade.getProject().getFolder(outputPath); return outputFolder; } private boolean isIncludeBndFileChange(BuildContext buildContext, Map<String, String> instructions) throws CoreException { for (String path : getIncludeBndFilePaths(instructions)) { // this does not detect changes in outside ${project.basedir} if (buildContext.hasDelta(path)) { return true; } } return false; } @Override public void clean(IProgressMonitor monitor) throws CoreException { IMavenProjectFacade facade = getMavenProjectFacade(); MavenProject mavenProject = facade.getMavenProject(monitor); @SuppressWarnings("unchecked") Map<String, String> instructions = maven.getMojoParameterValue(mavenProject, execution, "instructions", Map.class, monitor); if (isDeclerativeServices(mavenProject.getBasedir(), instructions)) { IFolder outputFolder = getOutputFolder(monitor, facade, execution); outputFolder.getFolder("OSGI-OPT").delete(true, monitor); outputFolder.getFolder("OSGI-INF").delete(true, monitor); } } }; }
From source file:org.sonatype.tycho.m2e.felix.internal.MavenBundlePluginConfigurator.java
License:Open Source License
protected static MojoExecution amendMojoExecution(MavenProject mavenProject, MojoExecution execution, Map<String, String> instructions) { if ("bundle".equals(execution.getGoal())) { // do not generate complete bundle. this is both slow and can produce unexpected workspace changes // that will trigger unexpected/endless workspace build. // we rely on the fact that ManifestPlugin mojo extends BundlePlugin and does not introduce any // additional required parameters, so can run manifest goal in place of bundle goal. MojoDescriptor descriptor = execution.getMojoDescriptor().clone(); descriptor.setGoal("manifest"); descriptor.setImplementation("org.apache.felix.bundleplugin.ManifestPlugin"); MojoExecution _execution = new MojoExecution(execution.getPlugin(), "manifest", "m2e-tycho:" + execution.getExecutionId() + ":manifest"); _execution.setConfiguration(execution.getConfiguration()); _execution.setMojoDescriptor(descriptor); _execution.setLifecyclePhase(execution.getLifecyclePhase()); execution = _execution;// w ww.j a va2 s .c o m } Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration()); if (VERSION_2_3_6.compareTo(new DefaultArtifactVersion(execution.getVersion())) <= 0) { setBoolean(configuration, "rebuildBundle", true); } if (isDeclerativeServices(mavenProject.getBasedir(), instructions)) { setBoolean(configuration, "unpackBundle", true); } execution.setConfiguration(configuration); return execution; }
From source file:org.sourcepit.b2.internal.generator.BootPomSerializer.java
License:Apache License
@Override public void startGeneration(ModuleDirectory moduleDirectory, AbstractModule module) { final MavenProject currentProject = legacySupport.getSession().getCurrentProject(); if (module.getDirectory().equals(currentProject.getBasedir())) { try {//w w w . j a va 2 s.c o m persistB2BootPom(module, currentProject); persistModulePomTemplate(module, currentProject); } catch (IOException e) { throw new IllegalStateException(e); } } }
From source file:org.sourcepit.b2.internal.maven.B2BootstrapParticipant.java
License:Apache License
public void beforeBuild(MavenSession bootSession, final MavenProject bootProject, MavenSession actualSession) { LOGGER.info(""); LOGGER.info("------------------------------------------------------------------------"); LOGGER.info("Bootstrapping " + bootProject.getName() + " " + bootProject.getVersion()); LOGGER.info("------------------------------------------------------------------------"); final List<File> projectDirs = new ArrayList<File>(); for (MavenProject project : bootSession.getProjects()) { projectDirs.add(project.getBasedir()); }//from w ww . j a v a2s. c o m final int idx = bootSession.getProjects().indexOf(bootProject); checkState(idx > -1); final B2Request b2Request = b2RequestFactory.newRequest(projectDirs, idx); final AbstractModule module = b2LifecycleRunner.prepareNext(projectDirs, idx, b2Request); bootProject.setContextValue(AbstractModule.class.getName(), module); bootProject.setContextValue(ModuleDirectory.class.getName(), b2Request.getModuleDirectory()); }
From source file:org.sourcepit.b2.internal.maven.MavenB2RequestFactory.java
License:Apache License
public B2Request newB2Request(MavenSession bootSession, MavenProject bootProject) { ModuleModelPackage.eINSTANCE.getClass(); final PropertiesSource moduleProperties = modulePropertiesFactory .createModuleProperties(legacySupport.getSession(), bootProject); final ResourceSet resourceSet = adapterFactory.adapt(bootSession, bootProject).getResourceSet(); processDependencies(resourceSet, bootSession, bootProject); final File moduleDir = bootProject.getBasedir(); LOGGER.info("Building model for directory " + moduleDir.getName()); final ITemplates templates = new DefaultTemplateCopier(Optional.of(moduleProperties)); final B2Request b2Request = new B2Request(); b2Request.setModuleProperties(moduleProperties); b2Request.setInterpolate(!converter.isSkipInterpolator(moduleProperties)); b2Request.setTemplates(templates); b2Request.setContentTypes(ContentTypes.DEFAULT); for (MavenProject project : bootSession.getProjects()) { final File projectDir = project.getBasedir(); if (!projectDir.equals(bootProject.getBasedir())) { final ModelContext modelContext = ModelContextAdapterFactory.get(project); if (modelContext != null) { final URI moduleUri = modelContext.getModuleUri(); final AbstractModule module = (AbstractModule) resourceSet.getEObject(moduleUri, true); b2Request.getModulesCache().put(module.getDirectory(), module); }//from w ww .ja v a 2s . com } } ModuleDirectory moduleDirectory = moduleDirectoryFactory.create(moduleDir, moduleProperties); b2Request.setModuleDirectory(moduleDirectory); return b2Request; }
From source file:org.sourcepit.b2.internal.maven.MavenB2RequestFactory.java
License:Apache License
private static MavenProject findMavenProject(MavenSession mavenSession, File directory) { for (MavenProject mavenProject : mavenSession.getProjects()) { if (mavenProject.getBasedir().equals(directory)) { return mavenProject; }/*from ww w . j a v a 2 s.com*/ } return null; }
From source file:org.sourcepit.b2.internal.maven.MavenResolutionContextResolver.java
License:Apache License
private static void assertIsModuleProject(final MavenProject project, AbstractModule module) { final String projectPath = project.getBasedir().getAbsolutePath(); final String modelPath = module.getDirectory().getAbsolutePath(); if (!modelPath.startsWith(projectPath)) { throw new IllegalStateException(); }/* w w w . j a v a 2 s . co m*/ }
From source file:org.sourcepit.b2.internal.maven.ModelContextAdapterFactory.java
License:Apache License
private ModelContext createModuleModelContext(MavenSession session, MavenProject project) { final ResourceSet resourceSet = createResourceSet(); final SetMultimap<URI, String> scopeTest = LinkedHashMultimap.create(); initURIMapping(resourceSet, scopeTest, session, project, "test"); final SetMultimap<URI, String> scopeCompile = LinkedHashMultimap.create(); initURIMapping(resourceSet, scopeCompile, session, project, "compile"); initURIMapping(resourceSet, session, project); final URI artifactURI = B2MavenBridge.toArtifactURI(project, "module", null); final URI fileURI = URI.createFileURI(pathOfMetaDataFile(project.getBasedir(), "b2.module")); resourceSet.getURIConverter().getURIMap().put(artifactURI, fileURI); return new ModelContext(resourceSet, artifactURI.appendFragment("/"), resolve(resourceSet, scopeCompile), resolve(resourceSet, scopeTest)); }
From source file:org.sourcepit.b2.maven.core.B2MavenBridge.java
License:Apache License
private static ResourceSet initResourceSet(MavenSession session) { final ResourceSet resourceSet = createResourceSet(); for (MavenProject mavenProject : session.getProjects()) { if (isModuleDir(mavenProject.getBasedir())) { setUriMappings(mavenProject.getBasedir(), resourceSet); }//from w w w . j a v a 2s .co m } return resourceSet; }