use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.
the class NarExecutionBuilder method build.
public NarExecution build(final String buildType) throws CoreException {
try {
NarExecution settings = new NarExecution(mojoExecution);
settings.setSkip(narCompileMojo.isSkip());
settings.setOS(narCompileMojo.getOS());
settings.setLinkerName(narCompileMojo.getLinker().getName());
List<NarBuildArtifact> artifactSettings = settings.getArtifactSettings();
if (NarExecution.MAIN.equals(buildType)) {
List<?> libraries = narCompileMojo.getLibraries();
for (Iterator<?> iter = libraries.iterator(); iter.hasNext(); ) {
ILibrary library = (ILibrary) iter.next();
NarBuildArtifact buildArtifact = buildArtifactSettings(library.getType(), buildType, library.linkCPP(), null);
buildArtifact.setArtifactName(narCompileMojo.getOutput(library.getType()));
buildArtifact.setConfigName(CdtUtils.getConfigName(mojoExecution, buildArtifact));
artifactSettings.add(buildArtifact);
}
} else if (NarExecution.TEST.equals(buildType)) {
List<?> tests = narCompileMojo.getTests();
for (Iterator<?> iter = tests.iterator(); iter.hasNext(); ) {
ITest test = (ITest) iter.next();
NarBuildArtifact buildArtifact = buildArtifactSettings(NarBuildArtifact.EXECUTABLE, buildType, true, test);
buildArtifact.setArtifactName(test.getName());
buildArtifact.setConfigName(CdtUtils.getTestConfigName(mojoExecution, buildArtifact));
artifactSettings.add(buildArtifact);
}
}
return settings;
} catch (MojoFailureException e) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo failure", e));
} catch (MojoExecutionException e) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo execution failed", e));
}
}
use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.
the class BuildPathManager method updateBuildPaths.
private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException {
final IMavenProjectFacade facade = projectManager.getProject(project);
if (facade != null) {
final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
final ICProjectDescription des = mngr.getProjectDescription(project, true);
if (des != null) {
boolean changed = false;
logger.debug("updateBuildPaths: project=" + project.getName());
final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager);
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
for (NarExecution narSettings : narExecutions) {
if (!narSettings.isSkip()) {
final String os = narSettings.getOS();
final String linkerName = narSettings.getLinkerName();
final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
changed = updateCdtBuildPaths(des, synchro, narSettings);
}
}
if (changed) {
mngr.setProjectDescription(project, des);
}
}
}
}
use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.
the class CProjectConfigurator method configure.
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
final ConfiguratorContext context = new ConfiguratorContext(maven, projectManager);
IProject project = request.getProject();
monitor.setTaskName(Messages.CProjectConfigurator_task_name + project.getName());
logger.info("configure");
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
// Set the first created configuration as active.
boolean setActive = true;
final IMavenProjectFacade facade = request.getMavenProjectFacade();
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
for (NarExecution narSettings : narExecutions) {
if (!narSettings.isSkip()) {
final String os = narSettings.getOS();
final String linkerName = narSettings.getLinkerName();
final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
final String toolchain = synchro.getToolchain();
for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) {
final String configName = artifactSettings.getConfigName();
final String cdtArtefactType = CdtUtils.convertArtefactType(artifactSettings.getType());
IToolChain tc = getToolChain(toolchain, cdtArtefactType);
ICProjectDescription desc = getCdtProject(project, tc, cdtArtefactType, monitor);
ICConfigurationDescription cfg = getCdtMavenConfig(project, desc, tc, cdtArtefactType, configName, setActive, monitor);
setActive = false;
synchro.fullSync(cfg, artifactSettings);
mngr.setProjectDescription(project, desc);
}
}
}
AbstractProjectConfigurator jConfig = LifecycleMappingFactory.createProjectConfigurator(JAVA_CONFIGURATOR_ID);
jConfig.configure(request, monitor);
// ensure CDT builder is after the Maven one
boolean changed = false;
IProjectDescription description = project.getDescription();
ICommand cdtBuilder = null;
ICommand mavenBuilder = null;
ArrayList<ICommand> newSpec = new ArrayList<ICommand>();
for (ICommand command : description.getBuildSpec()) {
if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && mavenBuilder == null) {
cdtBuilder = command;
} else {
newSpec.add(command);
}
if (IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
mavenBuilder = command;
if (cdtBuilder != null) {
newSpec.add(cdtBuilder);
changed = true;
}
}
}
if (changed) {
description.setBuildSpec(newSpec.toArray(new ICommand[newSpec.size()]));
project.setDescription(description, monitor);
}
}
use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.
the class MavenUtils method buildCompileNarExecutions.
public static List<NarExecution> buildCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException {
List<NarExecution> narExecutions = new ArrayList<NarExecution>();
List<MojoExecution> compileExecutions = MavenUtils.getCompileExecutions(context, facade, monitor);
for (MojoExecution compileExecution : compileExecutions) {
NarExecution narSettings = MavenUtils.readCompileSettings(context, facade, compileExecution, monitor);
narExecutions.add(narSettings);
}
return narExecutions;
}
use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.
the class AbstractDependencyMojo method resolveEclipseProject.
private EclipseNarLayout resolveEclipseProject(final Artifact artifact, final ConfiguratorContext context, IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
final IMavenProjectRegistry projectManager = context.getProjectManager();
if (!Artifact.SCOPE_COMPILE.equals(artifact.getScope()) && !Artifact.SCOPE_TEST.equals(artifact.getScope())) {
return null;
}
IMavenProjectFacade dependency = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
if (dependency == null || dependency.getFullPath(artifact.getFile()) == null) {
return null;
}
if (dependency.getProject().equals(facade.getProject())) {
return null;
}
getLog().debug("Found dependency project " + dependency.getProject().getName());
EclipseNarLayout layout = new EclipseNarLayout(getLog());
layout.setProject(dependency);
List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, dependency, monitor);
getLog().debug("Found " + narExecutions.size() + " compile executions");
com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact artifactSettings = null;
for (NarExecution narSettings : narExecutions) {
for (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact settings : narSettings.getArtifactSettings()) {
layout.addArtifactName(settings.getType(), settings.getArtifactName());
artifactSettings = settings;
}
}
if (artifactSettings != null) {
for (String includePath : artifactSettings.getCSettings().getIncludePaths()) {
layout.addIncludeDirectory(new File(includePath));
}
for (String includePath : artifactSettings.getCppSettings().getIncludePaths()) {
layout.addIncludeDirectory(new File(includePath));
}
return layout;
}
return null;
}
Aggregations