var myProject = new Project(); myProject.$get({id: 123}). .$promise.then( //success function( value ){/*Do something with value*/}, //error function( error ){/*Do something with error*/} )
function Project(){} function localTest() { new Project(1,2,3); // `Project` points to the local variable, // not the global constructor! //...some noise, causing you to forget that the `Project` constructor was used var Project = 1; // Evaluated first }
private void scan(String pattern) { LOGGER.fine("Scanning "+pattern+" for hs_err_pid files"); pattern = pattern.replace("%p","*").replace("%%","%"); File f = new File(pattern).getAbsoluteFile(); if (!pattern.contains("*")) scanFile(f); else {// GLOB File commonParent = f; while (commonParent!=null && commonParent.getPath().contains("*")) { commonParent = commonParent.getParentFile(); } if (commonParent==null) { LOGGER.warning("Failed to process "+f); return; // huh? } FileSet fs = Util.createFileSet(commonParent, f.getPath().substring(commonParent.getPath().length()+1), null); DirectoryScanner ds = fs.getDirectoryScanner(new Project()); for (String child : ds.getIncludedFiles()) { scanFile(new File(commonParent,child)); } } }
private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException { String classPath = manifest.getMainAttributes().getValue(attributeName); if(classPath==null) return; // attribute not found for (String s : classPath.split(separator)) { File file = resolve(archive, s); if(file.getName().contains("*")) { // handle wildcard FileSet fs = new FileSet(); File dir = file.getParentFile(); fs.setDir(dir); fs.setIncludes(file.getName()); for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { paths.add(new File(dir,included)); } } else { if(!file.exists()) throw new IOException("No such file: "+file); paths.add(file); } } }
/** * Runs Ant glob expansion. * * @return * A set of relative file names from the base directory. */ @Nonnull private static String[] glob(File dir, String includes, String excludes, boolean defaultExcludes) throws IOException { if(isAbsolute(includes)) throw new IOException("Expecting Ant GLOB pattern, but saw '"+includes+"'. See http://ant.apache.org/manual/Types/fileset.html for syntax"); FileSet fs = Util.createFileSet(dir,includes,excludes); fs.setDefaultexcludes(defaultExcludes); DirectoryScanner ds; try { ds = fs.getDirectoryScanner(new Project()); } catch (BuildException x) { throw new IOException(x.getMessage()); } String[] files = ds.getIncludedFiles(); return files; }
/** * Explodes the plugin into a directory, if necessary. */ private static void explode(File archive, File destDir) throws IOException { destDir.mkdirs(); // timestamp check File explodeTime = new File(destDir,".timestamp2"); if(explodeTime.exists() && explodeTime.lastModified()==archive.lastModified()) return; // no need to expand // delete the contents so that old files won't interfere with new files Util.deleteRecursive(destDir); try { Project prj = new Project(); unzipExceptClasses(archive, destDir, prj); createClassJarFromWebInfClasses(archive, destDir, prj); } catch (BuildException x) { throw new IOException("Failed to expand " + archive,x); } try { new FilePath(explodeTime).touch(archive.lastModified()); } catch (InterruptedException e) { throw new AssertionError(e); // impossible } }
public void scan(File dir, FileVisitor visitor) throws IOException { if(fixEmpty(includes)==null && excludes==null) { // optimization new Full().scan(dir,visitor); return; } FileSet fs = Util.createFileSet(dir,includes,excludes); fs.setDefaultexcludes(useDefaultExcludes); if(dir.exists()) { DirectoryScanner ds = fs.getDirectoryScanner(new org.apache.tools.ant.Project()); for( String f : ds.getIncludedFiles()) { File file = new File(dir, f); scanSingle(file, f, visitor); } } }
/** * Copies a single file by using Ant. */ public static void copyFile(@Nonnull File src, @Nonnull File dst) throws BuildException { Copy cp = new Copy(); cp.setProject(new org.apache.tools.ant.Project()); cp.setTofile(dst); cp.setFile(src); cp.setOverwrite(true); cp.execute(); }
Project p = new Project(); Application a = new Application(); a.setProject(p); p.getApplications().add(a); em.persist(p);
@Test public void testSetClasspathRef() { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setClasspathRef(new Reference(new Project(), "id")); assertNotNull("Classpath should not be null", Whitebox.getInternalState(antTask, "classpath")); }
private CheckstyleAntTask getCheckstyleAntTask(String configFile) throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setConfig(getPath(configFile)); antTask.setProject(new Project()); return antTask; }
@Test public void testCreateClasspath() { final CheckstyleAntTask antTask = new CheckstyleAntTask(); assertEquals("Invalid classpath", "", antTask.createClasspath().toString()); antTask.setClasspath(new Path(new Project(), "/path")); assertEquals("Invalid classpath", "", antTask.createClasspath().toString()); }
protected void setUp() throws Exception { super.setUp(); project = new Project(); project.init(); ProjectHelper.getProjectHelper().parse(project, antFile); FLAG = null; }
@Test public void testCheckerException() throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTaskStub(); antTask.setConfig(getPath(CONFIG_FILE)); antTask.setProject(new Project()); antTask.setFile(new File("")); try { antTask.execute(); fail("Exception is expected"); } catch (BuildException ex) { assertTrue("Error message is unexpected", ex.getMessage().startsWith("Unable to process files:")); } }
@Test public final void testNonExistentConfig() throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setConfig(getPath(NOT_EXISTING_FILE)); antTask.setProject(new Project()); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); try { antTask.execute(); fail("Exception is expected"); } catch (BuildException ex) { assertTrue("Error message is unexpected", ex.getMessage().startsWith("Unable to create Root Module: config")); } }
@Test public final void testNoConfigFile() throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setProject(new Project()); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); try { antTask.execute(); fail("Exception is expected"); } catch (BuildException ex) { assertEquals("Error message is unexpected", "Must specify 'config'.", ex.getMessage()); } }
@Test public final void testEmptyConfigFile() throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setConfig(getPath("InputCheckstyleAntTaskEmptyConfig.xml")); antTask.setProject(new Project()); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); try { antTask.execute(); fail("Exception is expected"); } catch (BuildException ex) { assertTrue("Error message is unexpected", ex.getMessage().startsWith("Unable to create Root Module: config")); } }
@Test public final void testConfigurationByResource() throws IOException { final CheckstyleAntTask antTask = new CheckstyleAntTask(); antTask.setProject(new Project()); antTask.setConfig(getPath(CONFIG_FILE)); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); final CheckstyleAntTask.Formatter formatter = new CheckstyleAntTask.Formatter(); final File outputFile = new File("target/ant_task_config_by_url.txt"); formatter.setTofile(outputFile); final CheckstyleAntTask.FormatterType formatterType = new CheckstyleAntTask.FormatterType(); formatterType.setValue("plain"); formatter.setType(formatterType); formatter.createListener(null); antTask.addFormatter(formatter); antTask.execute(); final List<String> output = FileUtils.readLines(outputFile, StandardCharsets.UTF_8); final int sizeOfOutputWithNoViolations = 2; assertEquals("No violations expected", sizeOfOutputWithNoViolations, output.size()); }
@Test public void testSetClasspath() { final CheckstyleAntTask antTask = new CheckstyleAntTask(); final Project project = new Project(); final String path1 = "firstPath"; final String path2 = "secondPath"; antTask.setClasspath(new Path(project, path1)); antTask.setClasspath(new Path(project, path2)); assertNotNull("Classpath should not be null", Whitebox.getInternalState(antTask, "classpath")); final Path classpath = Whitebox.getInternalState(antTask, "classpath"); assertTrue("Classpath contain provided path", classpath.toString().contains(path1)); assertTrue("Classpath contain provided path", classpath.toString().contains(path2)); }
private void untar(File archiveFile, File project) { Untar expand = new Untar(); expand.setProject(new Project()); expand.setDest(project); expand.setSrc(archiveFile); Untar.UntarCompressionMethod method = new Untar.UntarCompressionMethod(); method.setValue("gzip"); expand.setCompression(method); expand.execute(); }