1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.implementations;
19
20 import org.apache.maven.model.Model;
21 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
22 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
23 import org.jadira.dependencynavigator.assembler.Assembler;
24 import org.jadira.dependencynavigator.assembler.AssemblerException;
25 import org.jadira.dependencynavigator.controller.DependencyResolutionException;
26 import org.jadira.dependencynavigator.model.Artifact;
27 import org.jadira.dependencynavigator.model.ArtifactInitialisationException;
28 import org.jadira.dependencynavigator.model.PomFile;
29 import org.jadira.dependencynavigator.model.RootPom;
30
31 import java.io.BufferedReader;
32 import java.io.FileNotFoundException;
33 import java.io.IOException;
34
35 public abstract class Workspace {
36
37 public static final String ROLE = "org.jadira.dependencynavigator.implementations.Workspace";
38
39
40
41 protected RootPom root;
42
43 private Assembler assembler;
44
45 private Repository repository;
46
47 public abstract PomFile loadModulePom(String module);
48
49 public abstract String getPath(String moduleName);
50
51 public abstract void reloadPomFile() throws ArtifactInitialisationException;
52
53 public abstract boolean canCreateSnapshot();
54
55 public RootPom getRoot() {
56 return this.root;
57 }
58
59 protected PomFile loadPom(BufferedReader pomFile) {
60 try {
61 MavenXpp3Reader pomReader = new MavenXpp3Reader();
62 Model model = pomReader.read(new BufferedReader(pomFile));
63 return new PomFile(assembler.assemble(model, repository), null, Artifact.DEFAULT_SCOPE);
64 } catch (FileNotFoundException e) {
65 throw new DependencyResolutionException(e);
66 } catch (IOException e) {
67 throw new DependencyResolutionException(e);
68 } catch (XmlPullParserException e) {
69 throw new DependencyResolutionException(e);
70 } catch (ArtifactInitialisationException e) {
71 throw new DependencyResolutionException(e);
72 } catch (AssemblerException e) {
73 throw new DependencyResolutionException(e);
74 }
75 }
76 }