View Javadoc

1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   */
14  /*
15   * This file has been modified by Chris Pheby in accordance with Section 4.2
16   * of the Apache Software License
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       * the root of the pom hierarachy. this will be an entity in the workspace
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  }