Skip to content
Snippets Groups Projects
Verified Commit 63a91735 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Cleanup structure

parent 15264739
No related branches found
No related tags found
No related merge requests found
Pipeline #641 failed
Showing
with 260 additions and 31 deletions
......@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.justcode
package de.justjanne.gitversion
import org.gradle.api.Project
......
......
implementation-class=de.justjanne.androidsigning.AndroidSigningPlugin
implementation-class=de.justjanne.gitversion.GitVersionPlugin
implementation-class=de.justjanne.coverageconverter.CoverageConverterPlugin
implementation-class=de.kuschku.justcode.JustCodePlugin
MIT License
Copyright (c) 2020 Hannes Rosenögger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#!/usr/bin/env python
import sys
import xml.etree.ElementTree as ET
import re
import os.path
import time
# branch-rate="0.0" complexity="0.0" line-rate="1.0"
# branch="true" hits="1" number="86"
def find_lines(j_package, filename):
"""Return all <line> elements for a given source file in a package."""
lines = list()
sourcefiles = j_package.findall("sourcefile")
for sourcefile in sourcefiles:
if sourcefile.attrib.get("name") == os.path.basename(filename):
lines = lines + sourcefile.findall("line")
return lines
def line_is_after(jm, start_line):
return int(jm.attrib.get('line', 0)) > start_line
def method_lines(jmethod, jmethods, jlines):
"""Filter the lines from the given set of jlines that apply to the given jmethod."""
start_line = int(jmethod.attrib.get('line', 0))
larger = list(int(jm.attrib.get('line', 0)) for jm in jmethods if line_is_after(jm, start_line))
end_line = min(larger) if len(larger) else 99999999
for jline in jlines:
if start_line <= int(jline.attrib['nr']) < end_line:
yield jline
def convert_lines(j_lines, into):
"""Convert the JaCoCo <line> elements into Cobertura <line> elements, add them under the given element."""
c_lines = ET.SubElement(into, 'lines')
for jline in j_lines:
mb = int(jline.attrib['mb'])
cb = int(jline.attrib['cb'])
ci = int(jline.attrib['ci'])
cline = ET.SubElement(c_lines, 'line')
cline.set('number', jline.attrib['nr'])
cline.set('hits', '1' if ci > 0 else '0') # Probably not true but no way to know from JaCoCo XML file
if mb + cb > 0:
percentage = str(int(100 * (float(cb) / (float(cb) + float(mb))))) + '%'
cline.set('branch', 'true')
cline.set('condition-coverage', percentage + ' (' + str(cb) + '/' + str(cb + mb) + ')')
cond = ET.SubElement(ET.SubElement(cline, 'conditions'), 'condition')
cond.set('number', '0')
cond.set('type', 'jump')
cond.set('coverage', percentage)
else:
cline.set('branch', 'false')
def path_to_filepath(path_to_class, sourcefilename):
return path_to_class[0: path_to_class.rfind("/") + 1] + sourcefilename
def add_counters(source, target):
target.set('line-rate', counter(source, 'LINE'))
target.set('branch-rate', counter(source, 'BRANCH'))
target.set('complexity', counter(source, 'COMPLEXITY', sum))
def fraction(covered, missed):
return covered / (covered + missed)
def sum(covered, missed):
return covered + missed
def counter(source, type, operation=fraction):
cs = source.findall('counter')
c = next((ct for ct in cs if ct.attrib.get('type') == type), None)
if c is not None:
covered = float(c.attrib['covered'])
missed = float(c.attrib['missed'])
return str(operation(covered, missed))
else:
return '0.0'
def convert_method(j_method, j_lines):
c_method = ET.Element('method')
c_method.set('name', j_method.attrib['name'])
c_method.set('signature', j_method.attrib['desc'])
add_counters(j_method, c_method)
convert_lines(j_lines, c_method)
return c_method
def convert_class(j_class, j_package):
c_class = ET.Element('class')
c_class.set('name', j_class.attrib['name'].replace('/', '.'))
c_class.set('filename', path_to_filepath(j_class.attrib['name'], j_class.attrib['sourcefilename']))
all_j_lines = list(find_lines(j_package, c_class.attrib['filename']))
c_methods = ET.SubElement(c_class, 'methods')
all_j_methods = list(j_class.findall('method'))
for j_method in all_j_methods:
j_method_lines = method_lines(j_method, all_j_methods, all_j_lines)
c_methods.append(convert_method(j_method, j_method_lines))
add_counters(j_class, c_class)
convert_lines(all_j_lines, c_class)
return c_class
def convert_package(j_package):
c_package = ET.Element('package')
c_package.attrib['name'] = j_package.attrib['name'].replace('/', '.')
c_classes = ET.SubElement(c_package, 'classes')
for j_class in j_package.findall('class'):
c_classes.append(convert_class(j_class, j_package))
add_counters(j_package, c_package)
return c_package
def convert_root(source, target, source_roots):
try:
target.set('timestamp', str(int(source.find('sessioninfo').attrib['start']) / 1000))
except AttributeError as e:
target.set('timestamp', str(int(time.time() / 1000)))
sources = ET.SubElement(target, 'sources')
for s in source_roots:
ET.SubElement(sources, 'source').text = s
packages = ET.SubElement(target, 'packages')
for group in source.findall('group'):
for package in group.findall('package'):
packages.append(convert_package(package))
for package in source.findall('package'):
packages.append(convert_package(package))
add_counters(source, target)
def jacoco2cobertura(filename, source_roots):
if filename == '-':
root = ET.fromstring(sys.stdin.read())
else:
tree = ET.parse(filename)
root = tree.getroot()
into = ET.Element('coverage')
convert_root(root, into, source_roots)
print('<?xml version="1.0" ?>')
print(ET.tostring(into, encoding='unicode'))
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: cover2cover.py FILENAME [SOURCE_ROOTS]")
sys.exit(1)
filename = sys.argv[1]
source_roots = sys.argv[2:] if 2 < len(sys.argv) else '.'
jacoco2cobertura(filename, source_roots)
#!/usr/bin/env python
import sys
import xml.etree.ElementTree as ET
import lxml.etree
import re
import os.path
def convert_source(filename):
#read input file
root = lxml.etree.parse(filename)
sources = root.find('sources')
packages = root.find('packages')
for package in packages:
classes = package.find('classes')
for clazz in classes:
file_not_found = True
for source in sources:
full_filename = source.text + '/' + clazz.attrib['filename']
if os.path.isfile(full_filename):
clazz.attrib['filename'] = full_filename
file_not_found = False
if file_not_found:
print("Warning: File {} not found in all sources; removing from sources.".format(clazz.attrib['filename']))
clazz.getparent().remove(clazz)
data = lxml.etree.tostring(root, pretty_print=True)
#open the input file in write mode
fin = open(filename, "wb")
#overrite the input file with the resulting data
fin.write(data)
#close the file
fin.close()
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: source2filename.py FILENAME")
sys.exit(1)
filename = sys.argv[1]
convert_source(filename)
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.codecoverage
package de.justjanne.codecoverage
/**
* Used to mark inline functions as generated for jacoco
......
......
......@@ -32,7 +32,6 @@ org.gradle.caching=true
# Enable AndroidX
android.useAndroidX=true
android.enableJetifier=true
# Dependency versions
androidxAppcompatVersion=1.2.0
androidxCoreVersion=1.2.0
......
......
plugins {
kotlin("jvm")
id("jacoco")
id("de.justjanne.jacoco-cobertura-converter") version "1.0"
id("de.justjanne.jacoco-cobertura-converter")
}
tasks.withType<Test> {
......
......
......@@ -17,10 +17,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.io
package de.justjanne.libquassel.client.io
import info.quasseldroid.protocol.io.ChainedByteBuffer
import info.quasseldroid.libquassel.util.TlsInfo
import de.justjanne.libquassel.client.util.TlsInfo
import de.justjanne.libquassel.protocol.io.ChainedByteBuffer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.flow.MutableStateFlow
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.io
package de.justjanne.libquassel.client.io
import java.io.OutputStream
import java.util.zip.DeflaterOutputStream
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.io
package de.justjanne.libquassel.client.io
import java.io.InputStream
import java.nio.ByteBuffer
......
......
......@@ -17,9 +17,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.io
package de.justjanne.libquassel.client.io
import info.quasseldroid.libquassel.util.TlsInfo
import de.justjanne.libquassel.client.util.TlsInfo
import java.io.Flushable
import java.io.InputStream
import java.io.OutputStream
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.io
package de.justjanne.libquassel.client.io
import java.io.OutputStream
import java.nio.ByteBuffer
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.util
package de.justjanne.libquassel.client.util
import java.security.cert.Certificate
import java.security.cert.X509Certificate
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.util
package de.justjanne.libquassel.client.util
import java.io.ByteArrayInputStream
import java.security.cert.Certificate
......
......
......@@ -17,25 +17,25 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel
package de.justjanne.libquassel.client
import de.justjanne.bitflags.of
import de.justjanne.libquassel.client.io.CoroutineChannel
import de.justjanne.libquassel.client.testutil.QuasselCoreContainer
import de.justjanne.libquassel.client.testutil.TestX509TrustManager
import de.justjanne.libquassel.protocol.connection.*
import de.justjanne.libquassel.protocol.features.FeatureSet
import de.justjanne.libquassel.protocol.io.ChainedByteBuffer
import de.justjanne.libquassel.protocol.messages.handshake.*
import de.justjanne.libquassel.protocol.serializers.HandshakeSerializers
import de.justjanne.libquassel.protocol.serializers.handshake.ClientInitSerializer
import de.justjanne.libquassel.protocol.serializers.handshake.ClientLoginSerializer
import de.justjanne.libquassel.protocol.serializers.handshake.CoreSetupDataSerializer
import de.justjanne.libquassel.protocol.serializers.primitive.HandshakeMapSerializer
import de.justjanne.libquassel.protocol.serializers.primitive.IntSerializer
import de.justjanne.libquassel.protocol.variant.into
import de.justjanne.testcontainersci.api.providedContainer
import de.justjanne.testcontainersci.extension.CiContainers
import info.quasseldroid.libquassel.io.CoroutineChannel
import info.quasseldroid.libquassel.testutil.QuasselCoreContainer
import info.quasseldroid.libquassel.testutil.TestX509TrustManager
import info.quasseldroid.protocol.connection.*
import info.quasseldroid.protocol.features.FeatureSet
import info.quasseldroid.protocol.io.ChainedByteBuffer
import info.quasseldroid.protocol.messages.handshake.*
import info.quasseldroid.protocol.serializers.HandshakeSerializers
import info.quasseldroid.protocol.serializers.handshake.ClientInitSerializer
import info.quasseldroid.protocol.serializers.handshake.ClientLoginSerializer
import info.quasseldroid.protocol.serializers.handshake.CoreSetupDataSerializer
import info.quasseldroid.protocol.serializers.primitive.HandshakeMapSerializer
import info.quasseldroid.protocol.serializers.primitive.IntSerializer
import info.quasseldroid.protocol.variant.into
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertEquals
......
......
......@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package info.quasseldroid.libquassel.testutil
package de.justjanne.libquassel.client.testutil
import org.slf4j.LoggerFactory
import org.testcontainers.containers.BindMode
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment