1 package org.eclipse.aether.internal.impl.filter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.io.UncheckedIOException;
24 import java.nio.file.Path;
25
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilter;
28 import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource;
29 import org.eclipse.aether.util.ConfigUtils;
30 import org.eclipse.aether.util.DirectoryUtils;
31
32 import static java.util.Objects.requireNonNull;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public abstract class RemoteRepositoryFilterSourceSupport
52 implements RemoteRepositoryFilterSource
53 {
54 private static final String CONFIG_PROP_PREFIX = "aether.remoteRepositoryFilter.";
55
56 private static final String CONF_NAME_BASEDIR = "basedir";
57
58 static final String LOCAL_REPO_PREFIX_DIR = ".remoteRepositoryFilters";
59
60 private final String name;
61
62 protected RemoteRepositoryFilterSourceSupport( String name )
63 {
64 this.name = requireNonNull( name );
65 }
66
67
68
69
70 protected String configPropKey( String name )
71 {
72 return CONFIG_PROP_PREFIX + this.name + "." + name;
73 }
74
75
76
77
78
79
80 protected boolean isEnabled( RepositorySystemSession session )
81 {
82 return ConfigUtils.getBoolean( session, false, CONFIG_PROP_PREFIX + this.name );
83 }
84
85
86
87
88
89
90
91
92
93
94 protected Path getBasedir( RepositorySystemSession session, boolean mayCreate )
95 {
96 try
97 {
98 return DirectoryUtils.resolveDirectory(
99 session, LOCAL_REPO_PREFIX_DIR, configPropKey( CONF_NAME_BASEDIR ), mayCreate );
100 }
101 catch ( IOException e )
102 {
103 throw new UncheckedIOException( e );
104 }
105 }
106
107
108
109
110 protected static class SimpleResult implements RemoteRepositoryFilter.Result
111 {
112 private final boolean accepted;
113
114 private final String reasoning;
115
116 public SimpleResult( boolean accepted, String reasoning )
117 {
118 this.accepted = accepted;
119 this.reasoning = requireNonNull( reasoning );
120 }
121
122 @Override
123 public boolean isAccepted()
124 {
125 return accepted;
126 }
127
128 @Override
129 public String reasoning()
130 {
131 return reasoning;
132 }
133 }
134 }