Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add formatting, re-format according to rules #17

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# IDE Config and Code Style

This project has a strictly enforced code style. Code formatting is done by the Eclipse code
formatter, using the config files found in the `build-tools` directory. By
default when you run `mvn install` the code will be formatted automatically. When submitting a
pull request the CI build will fail if running the formatter results in any code changes, so it is
recommended that you always run a full Maven build before submitting a pull request.

If you want to run the formatting without doing a full build, you can run `mvn process-sources`.

#### Eclipse Setup

Open the *Preferences* window, and then navigate to _Java_ -> _Code Style_ -> _Formatter_. Click _
Import_ and then select the `eclipse-format.xml` file in the `build-tools`
directory.

Next navigate to _Java_ -> _Code Style_ -> _Organize Imports_. Click _Import_ and select
the `eclipse.importorder` file.

#### IDEA Setup

Open the _Preferences_ window (or _Settings_ depending on your edition), navigate to _Plugins_ and
install
the [Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter)
from the Marketplace.

Restart your IDE, open the *Preferences* (or *Settings*) window again and navigate to _Other
Settings_ -> _Eclipse Code Formatter_.

Select _Use the Eclipse Code Formatter_, then change the _Eclipse Java Formatter Config File_ to
point to the
`eclipse-format.xml` file in the `build-tools` directory. Make sure the _
Optimize Imports_ box is ticked, and select the `eclipse.importorder` file as the import order
config file.

Next, disable wildcard imports:
navigate to _Editor_ -> _Code Style_ -> _Java_ -> _Imports_
and set _Class count to use import with '\*'_ to `999`. Do the same with _Names count to use static
import with '\*'_.
16 changes: 16 additions & 0 deletions build-tools/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.metacosm</groupId>
<artifactId>power-server-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>build-tools</artifactId>


</project>
322 changes: 322 additions & 0 deletions build-tools/src/main/resources/eclipse-format.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions build-tools/src/main/resources/eclipse.importorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Organize Import Order
#Wed Jan 23 12:03:29 AEDT 2019
0=java
1=javax
2=jakarta
3=org
4=com
18 changes: 17 additions & 1 deletion metadata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,21 @@

<artifactId>power-server-metadata</artifactId>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>io.github.metacosm</groupId>
<artifactId>build-tools</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package io.github.metacosm.power;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class SensorMetadata {
public record ComponentMetadata(String name, int index, String description, boolean isAttributed, String unit){}
public record ComponentMetadata(String name, int index, String description, boolean isAttributed, String unit) {
}

@JsonCreator
public SensorMetadata(@JsonProperty("metadata") Map<String, ComponentMetadata> components, @JsonProperty("documentation") String documentation) {
public SensorMetadata(@JsonProperty("metadata") Map<String, ComponentMetadata> components,
@JsonProperty("documentation") String documentation) {
this.components = components;
this.documentation = documentation;
}
Expand Down
70 changes: 70 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
<quarkus.platform.version>3.7.0.CR1</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<formatter-plugin.version>2.23.0</formatter-plugin.version>
<impsort-plugin.version>1.9.0</impsort-plugin.version>
</properties>

<modules>
<module>build-tools</module>
<module>server</module>
<module>metadata</module>
</modules>
Expand Down Expand Up @@ -110,9 +113,76 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-plugin.version}</version>
<configuration>
<!-- Setting to 17 because the plugin does not support 21 -->
<compilerCompliance>17</compilerCompliance>
<configFile>eclipse-format.xml</configFile>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${impsort-plugin.version}</version>
<configuration>
<!-- Setting to 17 because the plugin does not support 21 -->
<compliance>17</compliance>
<groups>java.,javax.,jakarta.,org.,com.</groups>
<staticGroups>*</staticGroups>
<skip>${format.skip}</skip>
<removeUnused>true</removeUnused>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>format</id>
<activation>
<!-- This profile is effectively activated by default -->
<property>
<name>!no-format</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<id>format-sources</id>
<phase>process-sources</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<configuration>
<removeUnused>true</removeUnused>
</configuration>
<executions>
<execution>
<id>sort-imports</id>
<phase>process-sources</phase>
<goals>
<goal>sort</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<activation>
Expand Down
17 changes: 17 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,22 @@
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>io.github.metacosm</groupId>
<artifactId>build-tools</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.metacosm.power;

import java.time.Duration;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import io.github.metacosm.power.sensors.Measures;
import io.github.metacosm.power.sensors.PowerSensor;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.time.Duration;

@ApplicationScoped
public class PowerMeasurer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.metacosm.power;

import io.smallrye.mutiny.Multi;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

import org.jboss.resteasy.reactive.RestStreamElementType;

import io.smallrye.mutiny.Multi;

@Path("/power")
public class PowerResource {
@Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.metacosm.power.sensors;

import io.github.metacosm.power.SensorMeasure;

import java.util.Set;

import io.github.metacosm.power.SensorMeasure;

public interface Measures {
SensorMeasure missing = new SensorMeasure(new double[]{-1.0}, -1);
SensorMeasure missing = new SensorMeasure(new double[] { -1.0 }, -1);

RegisteredPID register(long pid);

void unregister(RegisteredPID registeredPID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package io.github.metacosm.power.sensors;

import io.github.metacosm.power.SensorMeasure;
import io.github.metacosm.power.SensorMetadata;

import java.util.Map;

public interface PowerSensor {

default void stop() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.github.metacosm.power.sensors;

import io.github.metacosm.power.sensors.linux.rapl.IntelRAPLSensor;
import io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Singleton;

import io.github.metacosm.power.sensors.linux.rapl.IntelRAPLSensor;
import io.github.metacosm.power.sensors.macos.powermetrics.MacOSPowermetricsSensor;

@Singleton
public class PowerSensorProducer {
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package io.github.metacosm.power.sensors.linux.rapl;

import io.github.metacosm.power.SensorMeasure;
import io.github.metacosm.power.SensorMetadata;
import io.github.metacosm.power.sensors.Measures;
import io.github.metacosm.power.sensors.PowerSensor;
import io.github.metacosm.power.sensors.RegisteredPID;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;

import io.github.metacosm.power.SensorMeasure;
import io.github.metacosm.power.SensorMetadata;
import io.github.metacosm.power.sensors.Measures;
import io.github.metacosm.power.sensors.PowerSensor;
import io.github.metacosm.power.sensors.RegisteredPID;

public class IntelRAPLSensor implements PowerSensor {
private final RAPLFile[] raplFiles;
Expand All @@ -37,7 +36,8 @@ public IntelRAPLSensor() {
for (String name : files.keySet()) {
metadata.put(name, new SensorMetadata.ComponentMetadata(name, fileNb++, name, false, "µJ"));
}
this.metadata = new SensorMetadata(metadata, "Linux RAPL derived information, see https://www.kernel.org/doc/html/latest/power/powercap/powercap.html");
this.metadata = new SensorMetadata(metadata,
"Linux RAPL derived information, see https://www.kernel.org/doc/html/latest/power/powercap/powercap.html");
lastMeasuredSensorValues = new double[raplFiles.length];
}

Expand Down Expand Up @@ -66,7 +66,6 @@ private static boolean isReadable(Path file) {
return Files.exists(file) && Files.isReadable(file);
}


@Override
public void start(long frequency) throws Exception {
this.frequency = frequency;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.github.metacosm.power.sensors.linux.rapl;

import java.util.HashSet;
import java.util.Set;

import io.github.metacosm.power.SensorMeasure;
import io.github.metacosm.power.sensors.Measures;
import io.github.metacosm.power.sensors.RegisteredPID;

import java.util.HashSet;
import java.util.Set;

public class SingleMeasureMeasures implements Measures {
private final Set<RegisteredPID> trackedPIDs = new HashSet<>();
private SensorMeasure measure;

void singleMeasure(SensorMeasure sensorMeasure) {
this.measure = sensorMeasure;
}
Expand Down Expand Up @@ -38,7 +39,7 @@ public int numberOfTrackerPIDs() {

@Override
public void record(RegisteredPID pid, SensorMeasure sensorMeasure) {
throw new UnsupportedOperationException("Shouldn't be needed");
throw new UnsupportedOperationException("Shouldn't be needed");
}

@Override
Expand Down
Loading
Loading