Skip to content

Commit

Permalink
SHRINKRES-63 "offline" feature placement reafactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatloka authored and kpiwko committed Nov 1, 2012
1 parent 6198f6f commit 16f7160
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ public interface MavenResolverSystemBase<EQUIPPEDRESOLVESTAGETYPE extends PomEqu
extends ResolverSystem,
PomlessResolveStageBase<EQUIPPEDRESOLVESTAGETYPE, UNEQUIPPEDRESOLVESTAGETYPE, STRATEGYSTAGETYPE, FORMATSTAGETYPE> {

/**
* Sets whether resolution should be done in "offline" (ie. not connected to Internet) mode.
*
* @param offline
* @return
*/
UNEQUIPPEDRESOLVESTAGETYPE offline(boolean offline);

/**
* Sets that resolution should be done in "offline" (ie. not connected to Internet) mode. Alias to
* {@link MavenResolverSystemBase#offline(boolean)}, passing <code>true</code> as a parameter.
*
* @return
*/
UNEQUIPPEDRESOLVESTAGETYPE offline();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,19 @@
public interface MavenStrategyStageBase<STRATEGYSTAGETYPE extends MavenStrategyStageBase<STRATEGYSTAGETYPE, FORMATSTAGETYPE>, FORMATSTAGETYPE extends MavenFormatStage>
extends TransitiveStrategyStage<MavenDependency, MavenResolutionFilter, FORMATSTAGETYPE, MavenResolutionStrategy> {

/**
* Sets whether resolution should be done in "offline" (ie. not connected to internet) mode.
*
* @param offline
* @return
*/
STRATEGYSTAGETYPE offline(boolean offline);

/**
* Sets that resolution should be done in "offline" (ie. not connected to internet) mode. Alias to
* {@link MavenStrategyStageBase#offline(boolean)}, passing <code>true</code> as a parameter.
*
* @param offline
* @return
*/
STRATEGYSTAGETYPE offline();

/**
* Sets that resolution from the ClassPath should be permitted in addition to configured repositories - defaults to
* "true"
*
* @param offline
* @param useClassPathResolution
* @return
*/
STRATEGYSTAGETYPE withClassPathResolution(boolean useClassPathResolution);

/**
* Sets whether to consult the Maven Central Repository in resolution; defaults to true.
*
* @param useMavenCentral
* @return
*/
STRATEGYSTAGETYPE withMavenCentralRepo(boolean useMavenCentral);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void dependencyInfo() {
*/
@Test
public void offline() {
Maven.resolver().resolve("groupId:artifactId:version").offline().withoutTransitivity().asSingle(File.class);
Maven.resolver().offline().resolve("groupId:artifactId:version").withoutTransitivity().asSingle(File.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,24 @@ public UNEQUIPPEDRESOLVESTAGETYPE addDependencies(Collection<MavenDependency> de
return delegate.addDependencies(dependencies);
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystemBaseImpl#offline(boolean)
*/
@Override
public UNEQUIPPEDRESOLVESTAGETYPE offline(final boolean offline) {
this.getSession().setOffline(offline);
return delegate;
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystemBaseImpl#offline()
*/
@Override
public UNEQUIPPEDRESOLVESTAGETYPE offline() {
return this.offline(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,6 @@ public boolean accepts(final MavenDependency coordinate, final List<MavenDepende

}

@Override
public STRATEGYSTAGETYPE offline(final boolean offline) {
// Set session offline flag via the abstraction
this.session.setOffline(offline);
return this.covarientReturn();
}

@Override
public STRATEGYSTAGETYPE offline() {
// Delegate
return this.offline(true);
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

/**
* Test cases for System property precedence in ShrinkWrap configuration
*
*
* @author <a href="mailto:kpiwko@redhat.com">Karel Piwko</a>
*
*
*/
public class SystemPropertyPrecedenceTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@

import org.jboss.shrinkwrap.resolver.api.NoResolvedResultException;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.ScopeType;
import org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder;
import org.jboss.shrinkwrap.resolver.impl.maven.util.TestFileUtil;
import org.jboss.shrinkwrap.resolver.impl.maven.util.ValidationUtil;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
Expand All @@ -54,6 +57,9 @@ public class OfflineRepositoryTestCase {

private static final int HTTP_TEST_PORT = 12345;

@Rule
public ExpectedException exception = ExpectedException.none();

/**
* Cleanup, remove the repositories from previous tests
*/
Expand All @@ -71,8 +77,6 @@ public void cleanup() throws IOException {
public void searchJunitOnOffineSettingsTest() {
Maven.configureResolver().fromFile("target/settings/profiles/settings-offline.xml")
.resolve("junit:junit:3.8.2").withTransitivity().as(File.class);

Assert.fail("Artifact junit:junit:3.8.2 should not be present in local repository");
}

/**
Expand All @@ -93,15 +97,29 @@ public void offlineProgramatically() throws IOException {
this.cleanup();

// Now try in offline mode and ensure we cannot resolve
boolean gotExpectedException = false;
try {
Maven.configureResolver().fromFile(settingsFile).resolve(artifactWhichShouldNotResolve).offline()
.withTransitivity().asSingle(File.class);
} catch (final NoResolvedResultException nre) {
gotExpectedException = true;
}
exception.expect(NoResolvedResultException.class);
Maven.configureResolver().fromFile(settingsFile).offline().resolve(artifactWhichShouldNotResolve)
.withTransitivity().asSingle(File.class);
}

/**
* Goes offline with .pom based resolver
*/
@Test
public void offlineProgramaticallyPomBased() throws IOException {
final String pomFile = "poms/test-parent.xml";

// Precondition; we can resolve when connected
final File[] files = Maven.resolver().loadPomFromClassLoaderResource(pomFile).importRuntimeDependencies().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-parent.tree"),
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);

Assert.assertTrue("Should not be able to resolve JUnit in offline mode", gotExpectedException);
// Manually cleanup; we're gonna run a test again
this.cleanup();

// Now try in offline mode and ensure we cannot resolve
exception.expect(NoResolvedResultException.class);
Maven.resolver().offline().loadPomFromClassLoaderResource(pomFile).importRuntimeDependencies().as(File.class);
}

/**
Expand Down

0 comments on commit 16f7160

Please sign in to comment.