1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.maven.plugin.eclipse; |
20 | |
|
21 | |
import java.io.File; |
22 | |
import java.io.FileInputStream; |
23 | |
import java.io.FileNotFoundException; |
24 | |
import java.io.FileOutputStream; |
25 | |
import java.io.IOException; |
26 | |
import java.io.OutputStream; |
27 | |
import java.util.Properties; |
28 | |
|
29 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
30 | |
import org.apache.maven.plugin.AbstractMojo; |
31 | |
import org.apache.maven.plugin.MojoExecutionException; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 1 | public class AddMavenRepoMojo |
40 | |
extends AbstractMojo |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public static final String DIR_ECLIPSE_PLUGINS_METADATA = ".metadata/.plugins"; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public static final String DIR_ECLIPSE_CORE_RUNTIME_SETTINGS = DIR_ECLIPSE_PLUGINS_METADATA |
54 | |
+ "/org.eclipse.core.runtime/.settings"; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public static final String FILE_ECLIPSE_JDT_CORE_PREFS = "org.eclipse.jdt.core.prefs"; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public static final String CLASSPATH_VARIABLE_M2_REPO = "org.eclipse.jdt.core.classpathVariable.M2_REPO"; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private String workspace; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
private ArtifactRepository localRepository; |
84 | |
|
85 | |
public void execute() |
86 | |
throws MojoExecutionException |
87 | |
{ |
88 | |
|
89 | 1 | File workDir = new File( workspace, DIR_ECLIPSE_CORE_RUNTIME_SETTINGS ); |
90 | 1 | workDir.mkdirs(); |
91 | |
|
92 | 1 | Properties props = new Properties(); |
93 | |
|
94 | 1 | File f = new File( workDir, FILE_ECLIPSE_JDT_CORE_PREFS ); |
95 | |
|
96 | |
|
97 | 1 | if ( f.exists() ) |
98 | |
{ |
99 | |
try |
100 | |
{ |
101 | 1 | props.load( new FileInputStream( f ) ); |
102 | |
} |
103 | |
catch ( FileNotFoundException e ) |
104 | |
{ |
105 | |
throw new MojoExecutionException( Messages |
106 | |
.getString( "EclipsePlugin.cantreadfile", f.getAbsolutePath() ), e ); |
107 | |
} |
108 | |
catch ( IOException e ) |
109 | |
{ |
110 | |
throw new MojoExecutionException( Messages |
111 | |
.getString( "EclipsePlugin.cantreadfile", f.getAbsolutePath() ), e ); |
112 | 1 | } |
113 | |
} |
114 | |
|
115 | 1 | props.put( CLASSPATH_VARIABLE_M2_REPO, localRepository.getBasedir() ); |
116 | |
|
117 | |
try |
118 | |
{ |
119 | 1 | OutputStream os = new FileOutputStream( f ); |
120 | 1 | props.store( os, null ); |
121 | 1 | os.close(); |
122 | |
} |
123 | |
catch ( IOException ioe ) |
124 | |
{ |
125 | |
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile", |
126 | |
f.getAbsolutePath() ) ); |
127 | 1 | } |
128 | 1 | } |
129 | |
|
130 | |
public ArtifactRepository getLocalRepository() |
131 | |
{ |
132 | |
return localRepository; |
133 | |
} |
134 | |
|
135 | |
public void setLocalRepository( ArtifactRepository localRepository ) |
136 | |
{ |
137 | 1 | this.localRepository = localRepository; |
138 | 1 | } |
139 | |
|
140 | |
public String getWorkspace() |
141 | |
{ |
142 | 1 | return workspace; |
143 | |
} |
144 | |
|
145 | |
public void setWorkspace( String workspace ) |
146 | |
{ |
147 | 1 | this.workspace = workspace; |
148 | 1 | } |
149 | |
} |