Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43a0977

Browse filesBrowse files
author
Igor Fedorenko
committed
Introduced ThreadBuildContext and couple of test BuildContext implementations
git-svn-id: file:///opt/svn/repositories/sonatype.org/spice/trunk/plexus-build-api@893 5751e0cb-dcb7-432f-92e2-260806df54be
1 parent 1f15d6b commit 43a0977
Copy full SHA for 43a0977

File tree

Expand file treeCollapse file tree

4 files changed

+288
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+288
-0
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ See the Apache License Version 2.0 for the specific language governing permissio
5252
<target>1.4</target>
5353
</configuration>
5454
</plugin>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-surefire-plugin</artifactId>
58+
<version>2.4.2</version>
59+
<configuration>
60+
<skipTests>true</skipTests>
61+
</configuration>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-jar-plugin</artifactId>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>test-jar</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
5574
</plugins>
5675
</build>
5776
</project>
+92Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
14+
package org.sonatype.plexus.build.incremental;
15+
16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.io.OutputStream;
19+
import java.util.List;
20+
21+
import org.sonatype.plexus.build.incremental.BuildContext;
22+
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
23+
import org.codehaus.plexus.util.Scanner;
24+
25+
/**
26+
* BuildContext implementation that delegates actual work to thread-local
27+
* build context set using {@link #setThreadBuildContext(BuildContext)}.
28+
* {@link DefaultBuildContext} is used if no thread local build context was set.
29+
*
30+
* Note that plexus component metadata is not generated for this implementation.
31+
* Apparently, older version of plexus used by maven-filtering and likely
32+
* other projects, does not honour "default" role-hint.
33+
*/
34+
public class ThreadBuildContext implements BuildContext {
35+
36+
private static final ThreadLocal threadContext = new ThreadLocal();
37+
38+
private static final DefaultBuildContext defaultContext = new DefaultBuildContext();
39+
40+
public static BuildContext getContext() {
41+
BuildContext context = (BuildContext) threadContext.get();
42+
if(context == null) {
43+
context = defaultContext;
44+
}
45+
return context;
46+
}
47+
48+
public static void setThreadBuildContext(BuildContext context) {
49+
threadContext.set(context);
50+
}
51+
52+
public boolean hasDelta(String relPath) {
53+
return getContext().hasDelta(relPath);
54+
}
55+
56+
public boolean hasDelta(List relPaths) {
57+
return getContext().hasDelta(relPaths);
58+
}
59+
60+
public Scanner newDeleteScanner(File basedir) {
61+
return getContext().newDeleteScanner(basedir);
62+
}
63+
64+
public OutputStream newFileOutputStream(File file) throws IOException {
65+
return getContext().newFileOutputStream(file);
66+
}
67+
68+
public Scanner newScanner(File basedir) {
69+
return getContext().newScanner(basedir);
70+
}
71+
72+
public Scanner newScanner(File basedir, boolean ignoreDelta) {
73+
return getContext().newScanner(basedir, ignoreDelta);
74+
}
75+
76+
public void refresh(File file) {
77+
getContext().refresh(file);
78+
}
79+
80+
public Object getValue(String key) {
81+
return getContext().getValue(key);
82+
}
83+
84+
public boolean isIncremental() {
85+
return getContext().isIncremental();
86+
}
87+
88+
public void setValue(String key, Object value) {
89+
getContext().setValue(key, value);
90+
}
91+
92+
}
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
14+
package org.sonatype.plexus.build.incremental.test;
15+
16+
import java.util.Map;
17+
18+
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
19+
20+
21+
public class TestFullBuildContext extends DefaultBuildContext {
22+
23+
private final Map context;
24+
25+
public TestFullBuildContext(Map context) {
26+
this.context = context;
27+
}
28+
29+
public void setValue(String key, Object value) {
30+
context.put(key, value);
31+
}
32+
33+
}
+144Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
Copyright (c) 2008 Sonatype, Inc. All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
14+
package org.sonatype.plexus.build.incremental.test;
15+
16+
import java.io.File;
17+
import java.io.FileOutputStream;
18+
import java.io.IOException;
19+
import java.io.OutputStream;
20+
import java.util.HashSet;
21+
import java.util.Iterator;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Set;
25+
26+
import org.codehaus.plexus.util.DirectoryScanner;
27+
import org.codehaus.plexus.util.Scanner;
28+
import org.sonatype.plexus.build.incremental.BuildContext;
29+
30+
31+
public class TestIncrementalBuildContext implements BuildContext {
32+
33+
private final File basedir;
34+
35+
private static final class TestScanner implements Scanner {
36+
private final File basedir;
37+
private final Set files;
38+
39+
private TestScanner(File basedir, Set files) {
40+
this.basedir = basedir;
41+
this.files = files;
42+
}
43+
44+
public void addDefaultExcludes() {
45+
}
46+
47+
public String[] getIncludedDirectories() {
48+
return new String[0];
49+
}
50+
51+
public String[] getIncludedFiles() {
52+
return (String[]) files.toArray(new String[files.size()]);
53+
}
54+
55+
public void scan() {
56+
}
57+
58+
public void setExcludes(String[] excludes) {
59+
}
60+
61+
public void setIncludes(String[] includes) {
62+
}
63+
64+
public File getBasedir() {
65+
return basedir;
66+
}
67+
}
68+
69+
private final Set changedFiles;
70+
71+
private final Set deletedFiles;
72+
73+
private final Map context;
74+
75+
76+
public TestIncrementalBuildContext(File basedir, Set files, Map context) {
77+
this(basedir, files, new HashSet(), context);
78+
}
79+
80+
public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) {
81+
this.basedir = basedir;
82+
this.changedFiles = changedFiles;
83+
this.deletedFiles = deletedFiles;
84+
this.context = context;
85+
}
86+
87+
public boolean hasDelta(String relpath) {
88+
String basepath = basedir.getAbsolutePath();
89+
90+
if (relpath.startsWith(basepath)) {
91+
relpath = relpath.substring(basepath.length() + 1);
92+
}
93+
94+
return changedFiles.contains(relpath) || deletedFiles.contains(relpath);
95+
}
96+
97+
public boolean hasDelta(List relpaths) {
98+
for(Iterator i = relpaths.iterator(); i.hasNext();) {
99+
String relpath = (String) i.next();
100+
if(hasDelta(relpath)) {
101+
return true;
102+
}
103+
}
104+
return false;
105+
}
106+
107+
public boolean isIncremental() {
108+
return true;
109+
}
110+
111+
public Scanner newDeleteScanner(File basedir) {
112+
return new TestScanner(basedir, deletedFiles);
113+
}
114+
115+
public OutputStream newFileOutputStream(File file) throws IOException {
116+
return new FileOutputStream(file);
117+
}
118+
119+
public Scanner newScanner(final File basedir) {
120+
return new TestScanner(basedir, changedFiles);
121+
}
122+
123+
public Scanner newScanner(File basedir, boolean ignoreDelta) {
124+
if(ignoreDelta) {
125+
DirectoryScanner directoryScanner = new DirectoryScanner();
126+
directoryScanner.setBasedir(basedir);
127+
return directoryScanner;
128+
}
129+
130+
return newScanner(basedir);
131+
}
132+
133+
public void refresh(File file) {
134+
}
135+
136+
public Object getValue(String key) {
137+
return context.get(key);
138+
}
139+
140+
public void setValue(String key, Object value) {
141+
context.put(key, value);
142+
}
143+
144+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.