1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.implementations.local;
19
20 import org.apache.maven.project.interpolation.ModelInterpolationException;
21 import org.codehaus.plexus.context.Context;
22 import org.codehaus.plexus.context.ContextException;
23 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
24 import org.jadira.dependencynavigator.controller.DependencyResolutionException;
25 import org.jadira.dependencynavigator.implementations.Workspace;
26 import org.jadira.dependencynavigator.model.ArtifactInitialisationException;
27 import org.jadira.dependencynavigator.model.PomFile;
28 import org.jadira.dependencynavigator.model.RootPom;
29
30 import java.io.BufferedReader;
31 import java.io.File;
32 import java.io.FileNotFoundException;
33 import java.io.FileReader;
34
35 public class LocalDiskWorkspace extends Workspace implements Contextualizable {
36
37 public static final String KEY_WORKSPACE_PATH = "local.workspace";
38
39 private File workspaceDirectory;
40
41 private File rootFile;
42
43 public File getWorkspaceDirectory() {
44 return this.workspaceDirectory;
45 }
46
47 public void loadRootPom(File file) throws ArtifactInitialisationException {
48 this.rootFile = file;
49 reloadPomFile();
50 }
51
52 @Override
53 public void reloadPomFile() throws ArtifactInitialisationException {
54 try {
55 BufferedReader fileReader = new BufferedReader(new FileReader(rootFile));
56 root = new RootPom(loadPom(fileReader), this);
57 } catch (FileNotFoundException e) {
58 throw new DependencyResolutionException(e);
59 } catch (ModelInterpolationException e) {
60 throw new DependencyResolutionException(e);
61 }
62 }
63
64 @Override
65 public String getPath(String moduleName) {
66 return rootFile.getParent() + "/" + moduleName + "/pom.xml";
67 }
68
69 @Override
70 public PomFile loadModulePom(String module) {
71 try {
72 File file2 = new File(getPath(module));
73 BufferedReader fileReader = new BufferedReader(new FileReader(file2));
74 return loadPom(fileReader);
75 } catch (FileNotFoundException e) {
76 throw new DependencyResolutionException(e);
77 }
78 }
79
80 @Override
81 public boolean canCreateSnapshot() {
82 return true;
83 }
84
85 public void contextualize(Context context) throws ContextException {
86 String workspacePath = (String) context.get(KEY_WORKSPACE_PATH);
87 if (workspacePath == null || workspacePath.trim().length() == 0) {
88 throw new ContextException("Missing configuration parameter: " + KEY_WORKSPACE_PATH);
89 }
90 workspaceDirectory = new File(workspacePath);
91 }
92 }