From 81b558651a3609dd8ac1bc731ae629f85178bab7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 12 May 2015 13:17:53 +0200 Subject: Week12 Find file --- Week12 Find File/build.xml | 73 + Week12 Find File/manifest.mf | 3 + Week12 Find File/nbproject/build-impl.xml | 1413 ++++++++++++++++++++ Week12 Find File/nbproject/genfiles.properties | 8 + Week12 Find File/nbproject/project.properties | 73 + Week12 Find File/nbproject/project.xml | 15 + .../src/com/camilstaps/findfile/FileFinder.java | 51 + .../com/camilstaps/findfile/Week12FindFile.java | 31 + 8 files changed, 1667 insertions(+) create mode 100644 Week12 Find File/build.xml create mode 100644 Week12 Find File/manifest.mf create mode 100644 Week12 Find File/nbproject/build-impl.xml create mode 100644 Week12 Find File/nbproject/genfiles.properties create mode 100644 Week12 Find File/nbproject/project.properties create mode 100644 Week12 Find File/nbproject/project.xml create mode 100644 Week12 Find File/src/com/camilstaps/findfile/FileFinder.java create mode 100644 Week12 Find File/src/com/camilstaps/findfile/Week12FindFile.java (limited to 'Week12 Find File') diff --git a/Week12 Find File/build.xml b/Week12 Find File/build.xml new file mode 100644 index 0000000..4362572 --- /dev/null +++ b/Week12 Find File/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project Week12 Find File. + + + diff --git a/Week12 Find File/manifest.mf b/Week12 Find File/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Week12 Find File/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Week12 Find File/nbproject/build-impl.xml b/Week12 Find File/nbproject/build-impl.xml new file mode 100644 index 0000000..eaaedb7 --- /dev/null +++ b/Week12 Find File/nbproject/build-impl.xml @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Week12 Find File/nbproject/genfiles.properties b/Week12 Find File/nbproject/genfiles.properties new file mode 100644 index 0000000..432b855 --- /dev/null +++ b/Week12 Find File/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=5918ea61 +build.xml.script.CRC32=6df53566 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=5918ea61 +nbproject/build-impl.xml.script.CRC32=5a02e2b1 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/Week12 Find File/nbproject/project.properties b/Week12 Find File/nbproject/project.properties new file mode 100644 index 0000000..8f369c2 --- /dev/null +++ b/Week12 Find File/nbproject/project.properties @@ -0,0 +1,73 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Week12_Find_File.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=com.camilstaps.findfile.Week12FindFile +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Week12 Find File/nbproject/project.xml b/Week12 Find File/nbproject/project.xml new file mode 100644 index 0000000..2ee98e9 --- /dev/null +++ b/Week12 Find File/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + Week12 Find File + + + + + + + + + diff --git a/Week12 Find File/src/com/camilstaps/findfile/FileFinder.java b/Week12 Find File/src/com/camilstaps/findfile/FileFinder.java new file mode 100644 index 0000000..80e06da --- /dev/null +++ b/Week12 Find File/src/com/camilstaps/findfile/FileFinder.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.findfile; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author camilstaps + */ +public class FileFinder implements Runnable { + + private final File rootDir; + private final String search; + + public FileFinder(String root, String search) throws IOException { + rootDir = new File(root); + if (!rootDir.exists() || !rootDir.isDirectory()) { + throw new IOException(root + " is not a directory."); + } + + this.search = search; + } + + @Override + public void run() { + find(rootDir, search); + } + + private void find(File dir, String name) { + File[] files = rootDir.listFiles(); + if (files == null) return; + for (File file : files) { + if (file.getName().equals(name)) { + System.out.println(file.getAbsolutePath()); + } + if (file.isDirectory()) { + try { + Thread t = new Thread(new FileFinder(file.getAbsolutePath(), search)); + t.start(); + t.join(); + } catch (IOException | InterruptedException ex) {} + } + } + } + +} diff --git a/Week12 Find File/src/com/camilstaps/findfile/Week12FindFile.java b/Week12 Find File/src/com/camilstaps/findfile/Week12FindFile.java new file mode 100644 index 0000000..4c59e7e --- /dev/null +++ b/Week12 Find File/src/com/camilstaps/findfile/Week12FindFile.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015 Camil Staps + */ +package com.camilstaps.findfile; + +import java.io.IOException; + +/** + * + * @author camilstaps + */ +public class Week12FindFile { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + if (args.length != 2) { + System.err.println("Usage: java Week12FindFile "); + System.exit(-1); + } + + try { + Thread t = new Thread(new FileFinder(args[0], args[1])); + t.start(); + } catch (IOException ex) { + System.err.println(ex.toString()); + } + } + +} -- cgit v1.2.3