Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 46458bf

Browse files
committed
inclus un fichier ant
1 parent 66ba496 commit 46458bf

File tree

7 files changed

+121
-19
lines changed

7 files changed

+121
-19
lines changed

.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="lib" path="lib/mongo-java-driver-2.13.2.jar"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>toolkit-java</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

MANIFEST.MF

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Manifest-Version: 1.0
2+
Ant-Version: Apache Ant 1.9.3
3+
Created-By: 1.7.0_79-b14 (Oracle Corporation)
4+
Main-Class: net.wekeypedia.main.Main
5+
Class-Path: lib/mongo-java-driver-2.13.2.jar
6+

build.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project basedir="." default="build" name="toolkit-java">
3+
<property environment="env"/>
4+
<property name="debuglevel" value="source,lines,vars"/>
5+
<property name="target" value="1.6"/>
6+
<property name="source" value="1.6"/>
7+
8+
<path id="toolkit-java.classpath">
9+
<pathelement location="bin"/>
10+
<pathelement location="lib/mongo-java-driver-2.13.2.jar"/>
11+
</path>
12+
13+
<target name="init">
14+
<mkdir dir="bin"/>
15+
<copy includeemptydirs="false" todir="bin">
16+
<fileset dir="src">
17+
<exclude name="**/*.launch"/>
18+
<exclude name="**/*.java"/>
19+
</fileset>
20+
</copy>
21+
</target>
22+
23+
<target name="doc" description="Generate the documentation.">
24+
<mkdir dir="doc"/>
25+
<javadoc sourcepath="src/" destdir="doc/">
26+
<classpath refid="toolkit-java.classpath" />
27+
<link href="http://docs.oracle.com/javase/7/docs/api/"/>
28+
<link href="http://api.mongodb.org/java/3.0/"/>
29+
</javadoc>
30+
</target>
31+
32+
<target name="clean">
33+
<delete dir="bin"/>
34+
<delete dir="doc"/>
35+
<delete file="wekeypedia.jar"/>
36+
</target>
37+
38+
<target depends="init" name="build">
39+
<echo message="${ant.project.name}: ${ant.file}"/>
40+
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
41+
<src path="src"/>
42+
<classpath refid="toolkit-java.classpath"/>
43+
</javac>
44+
</target>
45+
46+
<target name="Main">
47+
<java classname="net.wekeypedia.main.Main" failonerror="true" fork="yes">
48+
<classpath refid="toolkit-java.classpath"/>
49+
</java>
50+
</target>
51+
52+
<target name="jar" description="Package into executable JAR." depends="build">
53+
<jar destfile="wekeypedia.jar" basedir="bin" compress="true">
54+
<manifest>
55+
<attribute name="Main-Class" value="net.wekeypedia.main.Main"/>
56+
<attribute name="Class-Path" value="lib/mongo-java-driver-2.13.2.jar"/>
57+
</manifest>
58+
</jar>
59+
</target>
60+
61+
</project>

src/net/wekeypedia/main/Main.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
import net.wekeypedia.manager.MongoManager;
1616

1717

18-
18+
/** This class allowed the use of the toolkit through command line.
19+
*
20+
* @author jeremie
21+
*
22+
*/
1923
public class Main {
20-
24+
/** Read the list of titles of the pages to download.
25+
*
26+
* @param is
27+
* @return
28+
* @throws IOException
29+
*/
2130
public static List<String> getListOfNames(InputStream is) throws IOException{
2231
List<String> res = new LinkedList<String>();
2332
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
@@ -30,7 +39,9 @@ public static List<String> getListOfNames(InputStream is) throws IOException{
3039
return res;
3140
}
3241

33-
42+
/** Display the options of the command line.
43+
*
44+
*/
3445
public static void usage(){
3546
System.out.println("Usage: wikeypedia [OPTIONS]");
3647
System.out.println();
@@ -69,13 +80,13 @@ public static void main(String args[]){
6980
if(args[i].equals("-mongoDB")) mongoDB = args[++i];
7081
if(args[i].equals("-mongoCol")) mongoCollection = args[++i];
7182
}
72-
83+
7384
List<String> listNames = null;
7485
if (file==null) listNames = Main.getListOfNames(System.in);
7586
else listNames = Main.getListOfNames(new FileInputStream(file));
7687
int jobsize=1+listNames.size()*10/nbThread;
7788
JobManager JM = new JobManager(domain,listNames,jobsize);
78-
89+
7990
ManagerInterface MI = null;
8091
if (mongo){
8192
MongoManager MM = new MongoManager();
@@ -92,8 +103,9 @@ public static void main(String args[]){
92103
List<DownloadThread> threads = new LinkedList<DownloadThread>();
93104
for (int j=0;j<nbThread;j++) threads.add(new DownloadThread(JM,MI));
94105
for (DownloadThread df:threads) df.start();
95-
for (DownloadThread df:threads) df.wait();
106+
for (DownloadThread df:threads) df.join();
96107
}catch(Exception e){
108+
e.printStackTrace();
97109
Main.usage();
98110
}
99111
}

src/net/wekeypedia/manager/DownloadThread.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class DownloadThread extends Thread{
2323
public DownloadThread(JobManager jm, ManagerInterface mi) {
2424
super();
2525
this.mi=mi;
26+
this.jm=jm;
2627
this.downloadNames = new LinkedList<String>();
2728
}
2829

@@ -34,14 +35,10 @@ public void run(){
3435
while (jm.hasAnOtherJob()){
3536
List<String> dlnames=jm.getAJob();
3637
for (String name:dlnames){
37-
try{
3838
wp=mi.getWikiPage(jm.getDomain(),name);
3939
mi.saveWikiPage(wp);
4040
if (wp!=null) downloadNames.add(name);
41-
}catch(Exception e){
42-
e.printStackTrace();
43-
System.err.println("Error >> "+name);
44-
}
41+
4542
}
4643
}
4744
}

src/net/wekeypedia/manager/JobManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ public JobManager(String domain, List<String> names){
1616

1717
public JobManager(String domain, List<String> names,int jobSize){
1818
this.domain=domain;
19-
works=new HashMap<Integer,List<String>>();
20-
for (int i=0;i<=names.size()/jobSize;i++){
21-
works.put(i,new LinkedList<String>());
22-
}
23-
int i=0;
24-
for (String name :names) {
25-
works.get(i%works.size()).add(name);
26-
i++;
19+
works=new HashMap<Integer,List<String>>();
20+
if (names!=null && names.size()>0){
21+
for (int i=0;i<=names.size()/jobSize;i++){
22+
works.put(i,new LinkedList<String>());
23+
}
24+
int i=0;
25+
for (String name :names) {
26+
works.get(i%works.size()).add(name);
27+
i++;
28+
}
2729
}
2830
}
2931

0 commit comments

Comments
 (0)