/** * @return the Ivy instance based on the {@link #ivyConfName} * @throws AbortException * @throws ParseException * @throws IOException */ public Ivy getIvy(PrintStream logger) throws AbortException { Message.setDefaultLogger(new IvyMessageImpl()); File settingsLoc = (ivySettingsFile == null) ? null : new File(ivySettingsFile); if ((settingsLoc != null) && (!settingsLoc.exists())) { throw new AbortException( Messages.IvyModuleSetBuild_NoSuchIvySettingsFile(settingsLoc.getAbsolutePath())); } ArrayList<File> propertyFiles = new ArrayList<File>(); if (StringUtils.isNotBlank(ivySettingsPropertyFiles)) { for (String file : StringUtils.split(ivySettingsPropertyFiles, ',')) { File propertyFile = new File(workspaceProper, file.trim()); if (!propertyFile.exists()) { propertyFile = new File(file.trim()); if (!propertyFile.isAbsolute() || !propertyFile.exists()) { throw new AbortException(Messages.IvyModuleSetBuild_NoSuchPropertyFile(file)); } } propertyFiles.add(propertyFile); } } try { IvySettings ivySettings = new IvySettings(); for (File file : propertyFiles) { ivySettings.loadProperties(file); } if (settingsLoc != null) { ivySettings.load(settingsLoc); if (verbose) logger.println("Configured Ivy using custom settings " + settingsLoc.getAbsolutePath()); } else { ivySettings.loadDefault(); if (verbose) logger.println("Configured Ivy using default 2.1 settings"); } if (ivyBranch != null) { ivySettings.setDefaultBranch(ivyBranch); } return Ivy.newInstance(ivySettings); } catch (Exception e) { logger.println("Error while reading the default Ivy 2.1 settings: " + e.getMessage()); logger.println(e.getStackTrace()); } return null; }
public void testUpdate() throws Exception { /* * For updated file to be equals to updated.xml, we have to fix the line separator to the * one used in updated.xml, in order for this test to works in all platforms (default line * separator used in updater being platform dependent */ XmlModuleDescriptorUpdater.LINE_SEPARATOR = "\n"; File dest = new File("build/updated-test.xml"); dest.deleteOnExit(); Map resolvedRevisions = new HashMap(); resolvedRevisions.put( ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), "2.5"); resolvedRevisions.put( ModuleRevisionId.newInstance("yourorg", "yourmodule6", "trunk", "latest.integration"), "6.3"); Map resolvedBranches = new HashMap(); resolvedBranches.put(ModuleRevisionId.newInstance("yourorg", "yourmodule3", "3.1"), "branch1"); resolvedBranches.put( ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), null); GregorianCalendar cal = new GregorianCalendar(); cal.set(2005, 2, 22, 14, 32, 54); Ivy ivy = Ivy.newInstance(); ivy.setVariable("myvar", "myconf1"); XmlModuleDescriptorUpdater.update( XmlModuleUpdaterTest.class.getResource("test-update.xml"), dest, getUpdateOptions(ivy.getSettings(), resolvedRevisions, "release", "mynewrev", cal.getTime()) .setResolvedBranches(resolvedBranches)); assertTrue(dest.exists()); String expected = FileUtil.readEntirely( new BufferedReader( new InputStreamReader( XmlModuleUpdaterTest.class.getResourceAsStream("updated.xml")))); String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); assertEquals(expected, updated); }
public void testVariableReplacement() throws Exception { /* * For updated file to be equals to updated.xml, we have to fix the line separator to the * one used in updated.xml, in order for this test to works in all platforms (default line * separator used in updater being platform dependent */ XmlModuleDescriptorUpdater.LINE_SEPARATOR = "\n"; File dest = new File("build/updated-test2.xml"); dest.deleteOnExit(); Map resolvedRevisions = new HashMap(); resolvedRevisions.put( ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), "2.5"); resolvedRevisions.put( ModuleRevisionId.newInstance("yourorg", "yourmodule6", "trunk", "latest.integration"), "6.3"); Map resolvedBranches = new HashMap(); resolvedBranches.put(ModuleRevisionId.newInstance("yourorg", "yourmodule3", "3.1"), "branch1"); resolvedBranches.put( ModuleRevisionId.newInstance("yourorg", "yourmodule2", "branch1", "2+"), null); GregorianCalendar cal = new GregorianCalendar(); cal.set(2005, 2, 22, 14, 32, 54); Ivy ivy = Ivy.newInstance(); ivy.setVariable("myorg", "myorg"); ivy.setVariable("mymodule", "mymodule"); ivy.setVariable("myrev", "myrev"); ivy.setVariable("mystatus", "integration"); ivy.setVariable("mypubdate", "20050322143254"); ivy.setVariable("mylicense", "MyLicense"); ivy.setVariable("mylicenseurl", "http://www.my.org/mymodule/mylicense.html"); ivy.setVariable("myorgurl", "http://www.myorg.org/"); ivy.setVariable("ivyrep", "ivyrep"); ivy.setVariable("ivyrepurl", "http://www.jayasoft.fr/org/ivyrep/"); ivy.setVariable("ivyreppattern", "[organisation]/[module]/ivy-[revision].xml"); ivy.setVariable("ivys", "true"); ivy.setVariable("artifacts", "false"); ivy.setVariable("homepage", "http://www.my.org/mymodule/"); ivy.setVariable("includefile", "imported-configurations-with-mapping.xml"); ivy.setVariable("mydesc", "desc 1"); ivy.setVariable("visibility", "public"); ivy.setVariable("myvar", "myconf1"); ivy.setVariable("deprecated", "20050115"); ivy.setVariable("myartifact1", "myartifact1"); ivy.setVariable("mytype", "jar"); ivy.setVariable("mymodule2", "mymodule2"); ivy.setVariable("mymodule2rev", "2.0"); ivy.setVariable("changing", "true"); ivy.setVariable("transitive", "false"); ivy.setVariable("targetconf", "yourconf1"); ivy.setVariable("art9-1", "yourartifact9-1"); ivy.setVariable("conf3", "myconf3"); ivy.setVariable("includename", "your.*"); ivy.setVariable("includeext", "xml"); ivy.setVariable("excludename", "toexclude"); ivy.setVariable("excludemodule", "*servlet*"); ivy.setVariable("excludematcher", "glob"); ivy.setVariable("excludeorg", "acme"); ivy.setVariable("excludeartifact", "test"); ivy.setVariable("excludetype", "source"); ivy.setVariable("yourorg", "yourorg"); ivy.setVariable("yourmodule", ".*"); ivy.setVariable("all", "all"); ivy.setVariable("regexp", "regexp"); ivy.setVariable("theirrev", "1.0, 1.1"); XmlModuleDescriptorUpdater.update( XmlModuleUpdaterTest.class.getResource("test-update-withvar.xml"), dest, getUpdateOptions(ivy.getSettings(), resolvedRevisions, "release", "mynewrev", cal.getTime()) .setResolvedBranches(resolvedBranches)); assertTrue(dest.exists()); String expected = FileUtil.readEntirely( new BufferedReader( new InputStreamReader( XmlModuleUpdaterTest.class.getResourceAsStream("updated.xml")))); String updated = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))); assertEquals(expected, updated); }