### Eclipse Workspace Patch 1.0 #P ivy Index: test/java/org/apache/ivy/core/publish/PublishEngineTest.java =================================================================== --- test/java/org/apache/ivy/core/publish/PublishEngineTest.java (revision 885277) +++ test/java/org/apache/ivy/core/publish/PublishEngineTest.java (working copy) @@ -111,6 +111,90 @@ } resolveAndAssertFound(settings, resolver, "#A;1.0"); } + + /** + * Test that we can publish atomically into a maven-2 style repository + * (in which dotted organisation names are translated into multi-level + * directories, e.g. org.apache.ivy ==> org/apache/ivy). + */ + public void testM2Compatibility() throws Exception { + IvySettings settings = new IvySettings(); + final PublishEngine engine = new PublishEngine(settings, new EventManager()); + final int[] counter = new int[] {0}; + final Exception[] error = { null }; + + //use a dotted organisation name for the test. + final DefaultModuleDescriptor md = DefaultModuleDescriptor + .newDefaultInstance(ModuleRevisionId.parse("org.apache.ivy#A;1.0")); + final FileSystemResolver resolver = new FileSystemResolver() { + public void publish(Artifact artifact, File src, boolean overwrite) throws IOException { + super.publish(artifact, src, overwrite); + synchronized (PublishEngineTest.this) { + counter[0] ++; + } + sleepSilently(50); + synchronized (PublishEngineTest.this) { + counter[0] ++; + } + } + }; + + //set the resolver to m2 compatibility mode. + resolver.setName("test"); + resolver.setSettings(settings); + resolver.setM2compatible(true); + + //the organisation name should appear in the resolver's artifact path. + String publishRepoDir = new File("build/test/publish/repo").getAbsolutePath(); + resolver.addIvyPattern(publishRepoDir + "/[organisation]/[module]/[revision]/[artifact].[ext]"); + resolver.addArtifactPattern(publishRepoDir + "/[organisation]/[module]/[revision]/[artifact].[ext]"); + + FileUtil.copy( + new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), + new File("build/test/publish/module/A.jar"), null); + XmlModuleDescriptorWriter.write(md, new File("build/test/publish/module/ivy.xml")); + + resolveAndAssertNotFound(settings, resolver, "org.apache.ivy#A;latest.integration", "before publishing"); + + // run publish asynchronously + new Thread() { + public void run() { + try { + engine.publish( + md, + Arrays.asList(new String[] {"build/test/publish/module/[artifact].[ext]"}), + resolver, + new PublishOptions().setSrcIvyPattern("build/test/publish/module/[artifact].[ext]")); + synchronized (PublishEngineTest.this) { + counter[0] ++; + } + } catch (Exception e) { + //save exception to be rethrown in the test execution thread. + synchronized (PublishEngineTest.this) { + error[0] = e; + } + } + } + }.start(); + + while(true) { + sleepSilently(5); + synchronized (this) { + if (error[0] != null) { + //exception raised on publish thread -- rethrow it here to fail the test. + throw error[0]; + } + if (counter[0] == 5) { + break; + } else if (counter[0] < 4) { + resolveAndAssertNotFound(settings, resolver, + "org.apache.ivy#A;latest.integration", "after "+(counter[0] / 2)+" artifacts published"); + } + } + } + resolveAndAssertFound(settings, resolver, "org.apache.ivy#A;1.0"); + } + private void resolveAndAssertNotFound( IvySettings settings, FileSystemResolver resolver, String module, String context) throws ParseException {