1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks;
21
22 import java.io.File;
23
24 import com.github.maven_nar.cpptasks.compiler.ProcessorConfiguration;
25
26
27
28
29 public final class TargetInfo {
30 private static final File[] emptyFileArray = new File[0];
31 private final
32 private final
33 private boolean rebuild;
34 private final
35 private File[] sysSources;
36
37 public TargetInfo(final ProcessorConfiguration config, final File[] sources, final File[] sysSources,
38 final File output, boolean rebuild) {
39 if (config == null) {
40 throw new NullPointerException("config");
41 }
42 if (sources == null) {
43 throw new NullPointerException("sources");
44 }
45 if (output == null) {
46 throw new NullPointerException("output");
47 }
48 this.config = config;
49 this.sources = sources.clone();
50 if (sysSources == null) {
51 this.sysSources = emptyFileArray;
52 } else {
53 this.sysSources = sysSources.clone();
54 }
55 this.output = output;
56 this.rebuild = rebuild;
57
58
59
60 if (!output.exists()) {
61 rebuild = true;
62 }
63 }
64
65 public String[] getAllSourcePaths() {
66 final String[] paths = new String[this.sysSources.length + this.sources.length];
67 for (int i = 0; i < this.sysSources.length; i++) {
68 paths[i] = this.sysSources[i].toString();
69 }
70 final int offset = this.sysSources.length;
71 for (int i = 0; i < this.sources.length; i++) {
72 paths[offset + i] = this.sources[i].toString();
73 }
74 return paths;
75 }
76
77 public File[] getAllSources() {
78 final File[] allSources = new File[this.sources.length + this.sysSources.length];
79 System.arraycopy(this.sysSources, 0, allSources, 0, this.sysSources.length);
80 final int offset = this.sysSources.length;
81 System.arraycopy(this.sources, 0, allSources, 0 + offset, this.sources.length);
82 return allSources;
83 }
84
85 public ProcessorConfiguration getConfiguration() {
86 return this.config;
87 }
88
89 public File getOutput() {
90 return this.output;
91 }
92
93 public boolean getRebuild() {
94 return this.rebuild;
95 }
96
97
98
99
100
101 public SourceHistory[] getSourceHistories(final String basePath) {
102 final SourceHistory[] histories = new SourceHistory[this.sources.length];
103 for (int i = 0; i < this.sources.length; i++) {
104 final String relativeName = CUtil.getRelativePath(basePath, this.sources[i]);
105 final long lastModified = this.sources[i].lastModified();
106 histories[i] = new SourceHistory(relativeName, lastModified);
107 }
108 return histories;
109 }
110
111 public String[] getSourcePaths() {
112 final String[] paths = new String[this.sources.length];
113 for (int i = 0; i < this.sources.length; i++) {
114 paths[i] = this.sources[i].toString();
115 }
116 return paths;
117 }
118
119 public File[] getSources() {
120 final File[] clone = this.sources.clone();
121 return clone;
122 }
123
124 public String[] getSysSourcePaths() {
125 final String[] paths = new String[this.sysSources.length];
126 for (int i = 0; i < this.sysSources.length; i++) {
127 paths[i] = this.sysSources[i].toString();
128 }
129 return paths;
130 }
131
132 public File[] getSysSources() {
133 final File[] clone = this.sysSources.clone();
134 return clone;
135 }
136
137 public void mustRebuild() {
138 this.rebuild = true;
139 }
140 }