Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedwards committed Jun 3, 2015
2 parents b652102 + f1c8b12 commit 224465c
Show file tree
Hide file tree
Showing 28 changed files with 283 additions and 103 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target/
**/target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
4 changes: 2 additions & 2 deletions com.github.sdedwards.m2e-nar.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
6 changes: 6 additions & 0 deletions com.github.sdedwards.m2e-nar.tests/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
2 changes: 1 addition & 1 deletion com.github.sdedwards.m2e-nar.tests/it/it-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ under the License.
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
10 changes: 10 additions & 0 deletions com.github.sdedwards.m2e-nar.tests/it/it0003-jni/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ under the License.
<cpp>
<debug>true</debug>
</cpp>
<c>
<testOptions>
<testOption>-DTESTOPT="this is a nar-testCompile flag"</testOption>
</testOptions>
</c>
<libraries>
<library>
<type>jni</type>
Expand All @@ -65,6 +70,11 @@ under the License.
<include></include>
</includes>
</javah>
<tests>
<test>
<name>HelloWorld</name>
</test>
</tests>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <stdio.h>
#include "it0003_HelloWorldJNI.h"

#ifdef TESTOPT
#error "TESTOPT is set!"
#endif

JNIEXPORT jstring JNICALL Java_it0003_HelloWorldJNI_sayHello( JNIEnv *env, jobject obj ) {
jstring value; /* the return value */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <string.h>

#ifdef TESTOPT
char *testFlag = TESTOPT;
#else
char *testFlag = "testOption not set";
#endif

int main( int argc, const char* argv[] )
{
printf( "\nHello World C test:" );
if (strcmp(testFlag, "testOption not set") == 0) {
printf( "\nTest compiler option not set\n\n" );
return 1;
} else {
printf( "\nTest compiler option set: %s\n\n", testFlag );
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.github.sdedwards.m2e_nar;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -46,21 +50,17 @@
@SuppressWarnings("restriction")
public class AbstractTestBuild {

private static final String settingsFile = System
.getProperty("m2e_nar.settings");
// "target/it/interpolated-settings.xml";
private static final String settingsFile = System.getProperty("m2e_nar.settings");

protected static final String itPath = System.getProperty("m2e_nar.itPath",
"it");
protected static final String itPath = System.getProperty("m2e_nar.itPath", "it");

private IWorkspace workspace;

private IMavenConfiguration mavenConfiguration;

private String oldUserSettingsFile = null;

private File repo;

@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
workspace = ResourcesPlugin.getWorkspace();
Expand All @@ -71,8 +71,7 @@ public void setUp() throws Exception {
workspace.setDescription(description);

// Turn off index updating
IEclipsePreferences store = new DefaultScope()
.getNode(IMavenConstants.PLUGIN_ID);
IEclipsePreferences store = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID);
store.putBoolean(MavenPreferenceConstants.P_UPDATE_INDEXES, false);

mavenConfiguration = MavenPlugin.getMavenConfiguration();
Expand All @@ -82,22 +81,13 @@ public void setUp() throws Exception {
File settings = new File(settingsFile).getCanonicalFile();
if (settings.canRead()) {
String userSettingsFile = settings.getAbsolutePath();
System.out.println("Setting user settings file: "
+ userSettingsFile);
System.out.println("Setting user settings file: " + userSettingsFile);
mavenConfiguration.setUserSettingsFile(userSettingsFile);
} else {
fail("User settings file cannot be read: " + settings);
}
}

ArtifactRepository localRepository = MavenPlugin.getMaven()
.getLocalRepository();
if (localRepository != null) {
repo = new File(localRepository.getBasedir());
} else {
fail("Cannot determine local repository path");
}

cleanWorkspace();
waitForJobs();

Expand All @@ -112,8 +102,7 @@ public void tearDown() throws CoreException {

if (oldUserSettingsFile != null) {
// Restore the user settings file location
System.out.println("Restoring user settings file: "
+ oldUserSettingsFile);
System.out.println("Restoring user settings file: " + oldUserSettingsFile);
mavenConfiguration.setUserSettingsFile(oldUserSettingsFile);
}
}
Expand Down Expand Up @@ -149,29 +138,21 @@ protected List<IProject> importProject(final String path) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
final IProjectConfigurationManager configManager = MavenPlugin
.getProjectConfigurationManager();
final MavenModelManager mavenModelManager = MavenPlugin
.getMavenModelManager();
final IProjectConfigurationManager configManager = MavenPlugin.getProjectConfigurationManager();
final MavenModelManager mavenModelManager = MavenPlugin.getMavenModelManager();

final ProjectImportConfiguration configuration = new ProjectImportConfiguration();

final LocalProjectScanner scanner = new LocalProjectScanner(
workspace.getRoot().getLocation().toFile(), path,
true, mavenModelManager);
final LocalProjectScanner scanner = new LocalProjectScanner(workspace.getRoot().getLocation().toFile(), path, true, mavenModelManager);
scanner.run(monitor);

final List<MavenProjectInfo> projects = getProjects(scanner.getProjects());

workspace.run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor)
throws CoreException {
importResults.addAll(configManager.importProjects(
projects, configuration,
monitor));
public void run(IProgressMonitor monitor) throws CoreException {
importResults.addAll(configManager.importProjects(projects, configuration, monitor));
}
}, MavenPlugin.getProjectConfigurationManager().getRule(),
IWorkspace.AVOID_UPDATE, monitor);
}, MavenPlugin.getProjectConfigurationManager().getRule(), IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
return e.getStatus();
} catch (InterruptedException e) {
Expand All @@ -190,28 +171,54 @@ public void run(IProgressMonitor monitor)
createdProjects.add(p);
}
}
assertFalse("Could not create project " + path,
createdProjects.isEmpty());
assertFalse("Could not create project " + path, createdProjects.isEmpty());
return createdProjects;
}

protected IProject buildProject(final String projectPath)
throws CoreException, InterruptedException {
protected IProject buildProject(final String projectPath) throws CoreException, InterruptedException {
List<IProject> createdProjects = importProject(projectPath);
final IProject project = createdProjects.get(0);
validateCdtProject(project);

workspace.build(IncrementalProjectBuilder.FULL_BUILD, null);
waitForJobs();

buildAllConfigurations(project);

assertFalse("Build errors", hasErrorMarkers(project));

return project;
}

protected void buildAllConfigurations(final IProject project) {
final ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(project, false);
if (prjd != null) {
final ICConfigurationDescription[] cfgDescriptions = prjd.getConfigurations();
if (cfgDescriptions != null && cfgDescriptions.length > 0) {
final IConfiguration[] cfgs = new IConfiguration[cfgDescriptions.length];
for (int i=0; i < cfgDescriptions.length; ++i) {
cfgs[i] = ManagedBuildManager.getConfigurationForDescription(cfgDescriptions[i]);
}
final Job job = new Job("Building all configurations") {

@Override
protected IStatus run(IProgressMonitor monitor) {
try {
ManagedBuildManager.buildConfigurations(cfgs, monitor);
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
};
job.schedule();
waitForJobs();
}
}
}

private void validateCdtProject(IProject project) {
final MavenProjectManager projectManager = MavenPluginActivator
.getDefault().getMavenProjectManager();
final MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager();
final IMavenProjectFacade facade = projectManager.getProject(project);
assertNotNull(facade);
}
Expand Down Expand Up @@ -259,8 +266,7 @@ public boolean hasErrorMarkers(final IProject project) throws CoreException {
int errorCount = 0;
int warnCount = 0;
int infoCount = 0;
for (final IMarker marker : project.findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE)) {
for (final IMarker marker : project.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE)) {
final Object severity = marker.getAttribute(IMarker.SEVERITY);
final StringBuilder message = new StringBuilder();
if (severity != null) {
Expand All @@ -275,14 +281,11 @@ public boolean hasErrorMarkers(final IProject project) throws CoreException {
message.append("INFO: ");
}
}
System.out.println(message.toString()
+ marker.getAttribute(IMarker.MESSAGE) + " ("
+ marker.getResource().getName() + ":"
System.out.println(message.toString() + marker.getAttribute(IMarker.MESSAGE) + " (" + marker.getResource().getName() + ":"
+ marker.getAttribute(IMarker.LINE_NUMBER) + ")");
}
System.out.println(project.getName() + " has " + errorCount
+ " error marker(s), " + warnCount + " warning marker(s), "
+ infoCount + " info marker(s)");
System.out
.println(project.getName() + " has " + errorCount + " error marker(s), " + warnCount + " warning marker(s), " + infoCount + " info marker(s)");
return errorCount != 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class It0007Test extends AbstractTestBuild {
public void build() throws CoreException, InterruptedException {
final String projectPath = itPath + "/it0007-lib-shared";
final String buildArtifact = "nar-shared/libit0007-lib-shared-1.0-SNAPSHOT.so";
final String testArtifact = "nar-test-HelloWorldTest/HelloWorldTest";

IProject project = buildProject(projectPath);
assertTrue(project.exists(Path.fromOSString(buildArtifact)));
assertTrue(project.exists(Path.fromOSString(testArtifact)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class It0010Test extends AbstractTestBuild {
public void build() throws CoreException, InterruptedException {
final String projectPath = itPath + "/it0010-lib-static";
final String buildArtifact = "nar-static/libit0010-lib-static-1.0-SNAPSHOT.a";
final String testArtifact = "nar-test-HelloWorldTest/HelloWorldTest";

IProject project = buildProject(projectPath);
assertTrue(project.exists(Path.fromOSString(buildArtifact)));
assertTrue(project.exists(Path.fromOSString(testArtifact)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public void build() throws CoreException, InterruptedException {
IProject project = buildProject(projectPath);
assertTrue(project.exists(Path.fromOSString(buildArtifact)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public void build() throws CoreException, InterruptedException {
IProject project = buildProject(projectPath);
assertTrue(project.exists(Path.fromOSString(buildArtifact)));
}

}
Loading

0 comments on commit 224465c

Please sign in to comment.