View Javadoc
1   package org.codehaus.mojo.webstart.dependency;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.codehaus.mojo.webstart.dependency.task.JnlpDependencyTask;
24  
25  import java.io.File;
26  
27  /**
28   * Created on 1/4/14.
29   *
30   * @author Tony Chemit <chemit@codelutin.com>
31   * @since 1.0-beta-5
32   */
33  public class JnlpDependencyRequest
34  {
35  
36      private final JnlpDependencyConfig config;
37  
38      private final JnlpDependencyTask[] tasks;
39  
40      private final File originalFile;
41  
42      private final File finalFile;
43  
44      private final boolean uptodate;
45  
46      public JnlpDependencyRequest( JnlpDependencyConfig config, JnlpDependencyTask... tasks )
47      {
48          this.config = config;
49          this.tasks = tasks;
50  
51          originalFile = buildOriginalFile();
52          finalFile = buildFinalFile();
53  
54          File incomingFile = getConfig().getArtifact().getFile();
55  
56          long limitDate = incomingFile.lastModified();
57          uptodate = originalFile.exists() && originalFile.lastModified() > limitDate &&
58              finalFile.exists() && finalFile.lastModified() > limitDate;
59      }
60  
61      public JnlpDependencyConfig getConfig()
62      {
63          return config;
64      }
65  
66      public JnlpDependencyTask[] getTasks()
67      {
68          return tasks;
69      }
70  
71      public File getOriginalFile()
72      {
73          return originalFile;
74      }
75  
76      public boolean isUptodate()
77      {
78          return uptodate;
79      }
80  
81      public File getFinalFile()
82      {
83          return finalFile;
84      }
85  
86      private File buildOriginalFile()
87      {
88  
89          File workingDirectory = config.getWorkingDirectory();
90  
91          Artifact artifact = config.getArtifact();
92  
93          String fileName = config.getDependencyFilenameStrategy().getDependencyFilename( artifact, false, false );
94  
95          return new File( workingDirectory, fileName );
96      }
97  
98      private File buildFinalFile()
99      {
100 
101         File finalDirectory = config.getFinalDirectory();
102         String filename = config.getDependencyFilenameStrategy().getDependencyFilename( config.getArtifact(),
103                                                                                         config.isOutputJarVersion(),
104                                                                                         config.isUseUniqueVersions());
105         if ( config.isPack200() )
106         {
107             filename += ".pack";
108         }
109 
110         if ( config.isGzip() )
111         {
112             filename += ".gz";
113         }
114 
115         return new File( finalDirectory, filename );
116     }
117 }