Skip to content

Commit

Permalink
Make sure test dependencies are unpacked. Not all versions of nar-mav…
Browse files Browse the repository at this point in the history
…en-plugin

have the nar-test-unpack goal so we must do it by running the nar-testCompile
goal with an empty <tests> configuration element. This will unpack then compile
nothing.
  • Loading branch information
sdedwards committed May 21, 2015
1 parent c1ca07a commit 7b64e02
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<goal>nar-process-libraries</goal>
<goal>nar-testDownload</goal>
<goal>nar-testUnpack</goal>
<goal>nar-test-unpack</goal>
<goal>nar-testCompile</goal>
<goal>nar-test</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ public AbstractBuildParticipant getBuildParticipant(
return null;
} else if ("nar-testDownload".equals(goal)) {
return new MojoExecutionBuildParticipant(execution, false, true);
} else if ("nar-testUnpack".equals(goal)) {
} else if (MavenUtils.isTestUnpack(goal)) {
return new NarBuildParticipant(execution, false, true);
} else if ("nar-testCompile".equals(goal)) {
return null;
// Note that this does not actually compile the tests, only unpacks
// test dependencies for compatibility with older versions of
// nar-maven-plugin
return new NarTestCompileBuildParticipant(execution, false, true);
} else if ("nar-test".equals(goal)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public final class MavenUtils {
public static String NAR_COMPILE_GOAL = "nar-compile";
public static String NAR_TESTCOMPILE_GOAL = "nar-testCompile";

public static String NAR_TESTUNPACK_GOAL = "nar-testUnpack";
public static String NAR_TEST_UNPACK_GOAL = "nar-test-unpack";

private static final Logger logger = LoggerFactory.getLogger(MavenUtils.class);
private static ClassRealm realm = null;

Expand Down Expand Up @@ -131,7 +134,7 @@ public T call(IMavenExecutionContext context,
}, monitor);
}

public static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session,
private static <T extends AbstractMojo> T getConfiguredMojo(MavenSession session,
MojoExecution mojoExecution, Class<T> asType, Log log) throws CoreException {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

Expand Down Expand Up @@ -356,4 +359,9 @@ public static List<NarExecution> buildTestCompileNarExecutions(final Configurato
}
return narExecutions;
}

public static boolean isTestUnpack(String goal) {
return NAR_TESTUNPACK_GOAL.equals(goal) || NAR_TEST_UNPACK_GOAL.equals(goal);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* #%L
* Maven Integration for Eclipse CDT
* %%
* Copyright (C) 2014 Stephen Edwards
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.github.sdedwards.m2e_nar.internal;

import org.apache.maven.plugin.MojoExecution;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NarTestCompileBuildParticipant extends NarBuildParticipant {

private static final Logger logger = LoggerFactory.getLogger(CProjectConfigurator.class);

public NarTestCompileBuildParticipant(MojoExecution execution, boolean runOnIncremental, boolean runOnConfiguration) {
super(new MojoExecution(execution.getMojoDescriptor(), execution.getExecutionId(), execution.getSource())
, runOnIncremental, runOnConfiguration);
// Some versions of nar-maven-plugin don't have a nar-test-unpack goal
// this means the test artifacts won't be available to us.
// What we need to do is run the nar-testCompile goal without any tests its configuration
// in order to just unpack.
Xpp3Dom configuration = new Xpp3Dom(execution.getConfiguration());
logger.info("Configuration before: " + configuration);
for (int i = 0; i < configuration.getChildCount(); ++i) {
if ("tests".equals(configuration.getChild(i).getName())) {
configuration.removeChild(i);
break;
}
}
logger.info("Configuration after: " + configuration);
getMojoExecution().setConfiguration(configuration);
}

}

0 comments on commit 7b64e02

Please sign in to comment.